We recently just launched an iPhone app called Goo Goo Finder for Standard Candy, Co., one of our favorite clients. Creating an app wasn’t new to Paramore, but it was to me. I’ve developed applications and websites using a variety of languages over the years, but Objective-C wasn’t one of them, so this was a learning curve for me. Along the way, I learned five tips that might help others who are developing an iOS app, so I thought I’d share:
1. Get familiar with the language.
To get started, I spent some time in iTunes U watching the Stanford courses on iOS development. I was already familiar with the Model-View-Controller architecture, but the Stanford classes really helped me learn how to apply it to an iPhone application. I didn’t go through all of them (though I do still plan on it), but the few that I watched helped me overcome the intimidation factor of Objective-C. The instructor does a great job of helping programmers find some common ground to start from and learning from there.
2. Get familiar with the environment.
Once you feel ready to move forward, I recommend spending time in the XCode environment before you write a single line of code. Learn where things are, explore the menus, open the Organizer, Interface Builder, Instruments, and other built-in features. It can be frustrating to have to stop programming because you can’t find where something is in XCode, so take the time to do this.
3. Remember to watch your memory.
Unlike PHP, my weapon of choice, Objective-C forces you to keep track of allocated objects. If you allocate an array, for example, you are responsible for releasing the memory that holds that array. In PHP, you can create objects and variables on a whim, without any declaration or type-casting. This is nice, but can make you lazy and Objective-C will call you on the floor for it. Remembering to deallocate objects was by far the biggest growing pain I faced. While it’s true that the next iteration of XCode and iOS won’t make you deallocate objects, it’s still good practice to know when objects are accessible and when they aren’t. The iPhone isn’t a full computer, so don’t treat it like one. It’s a device that has limited memory and it’s your responsibility as a developer to use that memory responsibly.
4. Zombies are friends, not enemies.
Ignore what you’ve heard about zombies. They’re actually trying to help you, not kill you. If you do forget to deallocate an object, Objective-C will throw some cryptic error message that reads “EXC_BAD_ACCESS” and doesn’t really help you at all. This error means that you tried to access an object that was already deallocated, but it doesn’t tell you which object or where you tried to access it. That’s where Zombies come in. Apple realized this message wasn’t all that helpful, so they created an NSZombie object that retains the value of an object when its retain count drops to zero rather than deleting it. When you then try to access the object, it throws an exception and tells you where the object lives. You have to specifically enable NSZombies in Xcode as they’re disabled by default. Be sure to disable them again when you build for production. See? Zombies are friends after all.
5. Ask for help.
Don’t waste your time banging your head against a wall when you can’t figure something out. Chances are that someone else has had the same problem and is willing to share how they solved it. StackOverflow is a great resource. Luckily, I had Jesse Bunch in the office, though I tried not to bother him as much as possible. Developers are generally nice people and willing to help out the newbies, so just ask. Asking on StackOverflow will usually get you an answer in 30 minutes or less, which is a lot less time than you trying to figure it out on your own. Plus your head won’t hurt.