ios · objective-c · programming

iOS gotchas

I’m starting this list because I’ve been meaning to do so for a while, and I’d welcome suggestions (or corrections where I’ve misfired). Here are some silly things I’ve lost more time on than I should have. In some cases it was almost no time, because some kind soul had put up a blog post after they made the mistake. In other cases it took a while, so long in fact that I could have read all the relevant docs several times.

  1. CoreText draws upside down. This is because it uses an older coordinate system that starts at the lower left hand side of the screen rather than the upper left hand side of the screen. This could have taken me a long time to fix since I’ve only used CoreText once so far, but a Google search for `core text upside down` brought me to a very helpful blog post.
  2. Media Player libraries will often start your media playing as soon as you pick it, unless you tell it not to. This tripped me up in when I developed IdleReport because the videos users recorded were of idling vehicles, which don’t make much noise. So when I was testing the app with my phone I would sometimes thing I heard something but not be sure…If you don’t want automatic play (and most of the time you shouldn’t if you’re doing things properly…that is, asynchronously), there’s a property you can set on these sorts of classes.
  3. UIButton is surprisingly tricky. Even though you can access its title label for some purposes (I haven’t confirmed this, but off the top of my head I want to see its background color), you have to set its actual text via setTitle: forState:. Apparently this trips up a lot of folks, including me. I’ve made my peace with it as the cost of having nice responsive buttons without too much boilerplate, but it does trip up newbies just when they feel they are getting somewhere.
  4. UICollectionView is a tricky when you’ve got it inside a containing view. You have to watch out for which views can receive touches. The first time I set up a UICollectionView my containing view kept capturing the touches. It drove me crazy for three days…yes…that’s pretty embarrassing.

Objective-C was the first language I learned intensively and expressly to learn the language rather than because there was a pressing need. It taught me a bit about how to learn a language, and nowaways when I start something new, as soon as I start feeling not-too-bad about doing some basic tasks, I try to look up some gotcha-style blog posts. Here’s a few helpful ones for Objective-C.

  • Pivotal Labs’s Common iOS Gotchas
  • Big Nerd Ranch’s Testing Gotchas
  • A Medium post on Swift Gotchas
  • Quora on App Store Rejection Gotchas (to this I will add not putting in a battery disclaimer for MapKit, which was a gotcha I fell for…and for some reason they made me start over rather than simply edit the app description…sigh)

Objective-C can feel especially punishing when you get past the newbie phase because, while the API is mostly highly consistent, there are these kinds of gotchas. It’s best to push on. You’ll never keep it all in your head, but the painful experiences will give you a distant memory along with some keywords to rediscover traps for the uninitiated.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s