How to Program for the iPhone – A Plan
This is not so much how to make applications for the iPhone, since there are so many on of those on the web already. This is more a syllabus on how to get started with the vast amount of information already out there and where to start from to quickly become proficient at iPhone development without getting frustrated or discouraged.
Development Requirements
An Intel-based Apple Mac
$99 (optional – if you want to actually publish your app)
That’s all!
Apple Developer Account
Development for the iPhone is initially free. So feel free to head over to http://developer.apple.com and sign up for a developer account if you don’t already have one. This will give you access to the Integrated Development Environment (IDE) called XCode, which is required to develop applications for the iPhone and iPod Touch. It also serves as a treasure chest of free information, sample code, tutorials, how-to videos and news, all of which I’ll talk about how to use later.
Once you’ve signed up for a developer account, you’ll need to download XCode and install it on your Mac. PC users are, as they always are, out of luck since a Mac is required for development. Once that’s done, put it aside as you won’t need it for a bit.
Learn to Program
An Important Design Pattern: Model View Controller
If you already know how to program a little bit, but haven’t gone through the rigors of a four year university Computer Science degree or something similar, start with learning an important design patterns, namely one called Model View Controller (MVC). Of course, a 4-year degree is not necessary, but you need to understand basic software engineering principles, design patterns and basic usability practices, which practically none of the programming tutorials, books and online articles teach. Also, a lot of practice helps as you’ll learn how to fix non-obvious compiler and runtime errors, how to structure your code, and pitfalls of each language you use.
Objective-C: The Language of Choice
After you understand the basic principle of MVC, you can then move on to learning the language of choice, Objective-C. Why Objective-C? Why didn’t Apple just choose a common language like C++ or Java? The reasons will become obvious as you learn about the language, it’s power, and how it fits into the MVC methodology better than any other language you’ve likely seen before. So here’s a nice tutorial on how to program in Objective-C.
If you already have a great understanding of programming and know a C-based langauge, skip the lengthy tutorial and take a look at this primer to get a sense of the additions to C that Objective-C brings to the table. For most people who are familiar with a C-based language, this will be all you need to get started.
The Cocoa Framework: Because Reinventing the Wheel is for Marketing Types
Ok, great. Now you speak the language, but you need to know the framework and how the language leverages this technology so you don’t have to reinvent the wheel. Take a look at Cocoa Fundamentals to learn how the fundamentals of Cocoa work. The Cocoa framework is a superset of the Cocoa Touch framework that is specialized to fit the paradigm and requirements of the iPhone and iPod Touch devices. Knowledge of the Cocoa framework is essential to understanding how to use such things as data structures and containers, user interface (UI) elements and the rich built-in functionality that all these components offer you for free. Many of the Cocoa framework elements carry over into Cocoa Touch, such as strings, CoreData, CoreAudio, CoreAnimation and concepts such as delegation, protocols, interfaces and application bundles.
XCode Tools: The Real Workers
Once you know how to speak the language and use the technology, you need to know how to use the tools to make it all happen. Here’s another Apple document that explains what XCode is and how to use it. Even if you’ve worked in XCode before, it’s worth checking out as XCode is a powerful code editor, debugger and provides a host of other tools and features. If you’re interested in what else XCode has to offer, there’s a more detailed explanation of the other tools that come with XCode.
Your First iPhone Application
You need to keep in mind that even though this is a lot of information to process, if you’re unfamiliar with the platform, it’s all very intuitive and will become second nature with a little practice and time. Just keep looking at a little bit every day and re-read some of the things you read early on. No one can learn a foreign language in a week, so don’t expect to be fluent in everything Objective-C and Cocoa in less than that. Spend a little time with it every day, go through sample code that interests you, read developer forums to see what other people are having trouble with and come up with a few of your own app ideas just to put all this theory to work. You never truly learn something until you have to use it in the real world.
So now that you have made all the theory, concepts and language familiar to you, you can cement it in your brain with your first iPhone application. This tutorial will cover most of the concepts you already learned (repetition is the key to really cementing that knowledge) but it will also show how they all tie together, which is the most important part. Don’t just copy and paste the code. You don’t have to memorize it, but typing it out really helps you recognize the code later when you have to use it on your own.
Beyond the Basics
This is where most tutorials stop. They pat you on the back, call you an iPhone developer and send you on your way to flail your way through haphazard development. All you really know however is how to put a few buttons on the screen and make them do something stupid (which admittedly is most of the apps that are available on the app store). There’s a lot more you need to know to be truly dangerous.
Usabilty on the iPhone: The Apple Human Interface Guidelines (HIG)
Take an afternoon and sit down and read the Apple Human Interface Guidelines. This will give you a slew of iPhone capabilities, but more importantly, it’ll give you a sense of how to properly use the interface elements of the iPhone. Nothing shows an amateur or know-nothing developer than an improper use of an interface element or using a certain interface element because it looks or acts cool (anyone remember the drawer?).
Developing iPhone Apps:
Gather those Building Blocks
Create an iPhone Utility Application
iPhone utility applications are the easiest to understand. They have two views, a front side and a back side. This type of app is great for learning how two views can communicate without worrying about complex data structures, implementing confusing protocols or dealing with the frustration when your code compiles, but doesn’t work. You can also experiment with new technologies such as CoreData, CoreAnimation, CoreAudio, WebViews, playing music or anything else you’re interested in without the overhead of managing views and other complexities like that. Keep it simple and think of a few ideas that fit the paradigm of an iPhone utility application.
Navigation Controller: Controlling Presentation
After you’ve successfully completed a working iPhone utility application, the next and most common interface technology is the Navigation Controller. This is the controller that allows you to hit a button and have a new view slide in from the right. I love this controller because it adds a lot of functionality to your app without a lot of work. Simply allocate a new view, push it onto the navigation controller and release it because the navigation controller does the rest.
Tab Bar Controller: Multiple Sections in One App
The Tab Bar Controller is a great way to segment your applications into features. It’s a bit trickier to set up, but once you know how it works it’s intuitive and flexible. For example, you can use the views that Interface Builder gives you to drop your UI elements onto, or you can tell Interface Builder to load a particular View Controller of your choice. It greatly extends your application’s functionality with minimal work.
Tableview Controller Class: Displaying Your Data
Table views are a bit more complex and involve a bit more understanding but it’s hard to get far in iPhone development without using a tableview. Invest the time to understand these creatures and it’ll give you a nice return on your investment. Take a look at the TableViewSuite sample code to learn how to do everything you ever wanted to with table views.
Tool Bar: Making Your App Accomplish Something Useful
Applications need to do something useful besides editing data. Sometimes you may want to do something a little bit different and adding a tool bar to your application is a great way to add a different kind of functionality. It’s simple to use and gives you a standard way to manipulate data in your application.
Core Data: Handling Lots of Data Without Too Much Real Work
A lot of your app ideas are going to be based on having lots of useful data that needs to be displayed and manipulated and Core Data is the easiest, most flexible and optimized way to do that. So spend some time and read the Core Data Programming Guide. Secondly, it’s important to learn how to use a fetch results controller as it will allow you to display your data in a tableview in a simpler way than straight out of the fetch request. It will also give you the functionality of indexed tableviews for free (as seen in the Contacts application).
More Programming for iPhone
This is the one of the best paths to picking up programming for the iPhone. It starts you off with the most useful items without overwhelming you. However, it does take a lot of time to read and a little more than that to understand, but take it slowly, look at it over a course of several weeks and soon you’ll be able to add anything to your application by only reading the API references.
There are a ton of things that you’ll need to learn in order to be an effective developer, so in future articles I’ll take what I’ve learned, some pitfalls and neat tricks and show you some of the basic stuff that you can’t find in the Apple developer documentation such as handling common problems, design patterns and usability pitfalls.
After all of this, you’re still not done. You’ve only grasped the basics, but at this point, the real challenge is not understanding the technologies, it’s figuring out where to go from here: what should you learn next, how can you get started programming a real app, and most importantly how you can make a lot of money. All of this will be covered in future articles as this one is too long already, but I will leave you with some of my favorite links. In the mean time, subscribe via RSS or email to get future articles on iPhone and everything else I do. Finally, frequent the Apple developer forums and try to answer some of the questions there. You won’t always know the answer, but a little research and you will be able to figure it out and learn in the process.
Additional Links
Stack Overflow – A great site for asking programming questions of all kinds.
iPhone Dev SDK – Forum-based site for asking and answering everything iPhone related.
iPhone SDK Articles – Blog-based site with lots of useful and informative examples on iPhone development.
My Apple Background
I’ve been developing Mac applications since 2003, attending WWDC 2004 and 2005. I’m the author of several small Mac applications including a Terminal GUI tool that’s been quite popular in the past. I have taught Code Kitchens at Virginia Tech on Cocoa through the Mac Users Group and I use to sell, support, demonstrate and evangelize Apple products to college kids as an Apple Campus Rep. I’m now an independent developer, working in partnership with LTZ, a company started to give independent developers and free thinkers a platform and voice from which to launch their apps or app ideas.
0 Comments on “How to Program for the iPhone – A Plan”