Let’s say I have an idea for a useful little program for the iPhone.
I have a good idea of what goes on in computers, but I don’t have a lot of programming experience beyond, say, noodling around with C years ago. I know there’s a free downloadable “iPhone software development kit” and I know that there’s a set of developer tools that come with Macs these days, but I have no idea how to use them. I have a Mac.
What do I need to learn in order to program the iPhone, and what order do I need to learn it in?
Okay, I’ve signed up as a “registered iPhone developer”. Apple sent me a confirmation email, I followed a link to their developer pages and logged in, and I’m presented with a welcome page of links for the SDK, for tutorials, for all kinds of things. Now let’s see whether I can go from the absolute beginning using these tools and tutorials.
(Incidentally, the SDK is around 1.25 gigabytes. Good thing I cleared all that stuff out of my hard drive…)
Objective-C is a superset of C: basically SmallTalk syntax dropped into the C language to allow the type of object oriented programming they need. If you know C and the basics of object-oriented programming, it takes about 3 hours to come up to speed in Objective-C, and about 3 days to be an expert (the language is really small). If you prefer C++, the same extensions work there.
The unpaid developer kit comes with a simulator for your Mac, so you don’t need to spend money to try it out.
Assuming you have basic programming knowledge, the biggest hurdles are Interface Builder (the GUI designer), and particularly the interface between it and the programming language: views, view controllers, other controllers, and the like. This is far harder than learning Objective-C itself, and since it controls what actually appears on the screen, it can be hard to debug. I strongly recommend getting a book that comes with example code so you can start from a working model for your first app (there are also working templates in XCode that will get you started, but they’re “empty shells”).
I recommend this book for novices with a little programming background.
Note that if you like it, programming for your Mac is the same language and many of the same libraries. The user interface layer is different (UIxxx vs. NSxxx), but uses many of the same concepts, although the Mac Interface Builder connections are much more sophisticated. There’s some sense in starting out with Mac programing, then moving to iOS: the cannonical reference there is this, although it’s getting a little out of date unless there’s a newer edition. You’ll be able to move a lot of your code from one environment to the other, so you can use a Mac version as a sort of prototype for much of your non-UI code.
Also be aware that Stanford University has posted the entire class lectures of iphone App Programming from spring 2009 onto iTunes U. I have downloaded that to my iPad and would highly recommend that.
The great thing about this, is that you can do all of your programing for free, and only pay the fee once you actually have something you want on your phone. That way, you don’t blow your money on something that you never get around to finishing. That’s good for people like me that are easily distracted.
The programming environment is extremely advanced. I only wish I had someone to explain what all those crazy commands the gui environment generates are.
IBOutlet (prepended to instance variable declarations) is basically a #define to nothing: it’s just a marker for InterfaceBuilder that this particular variable should be visible (“have an outlet”) in the GUI construction tools so it can be wired up to things visually.
IBAction (the return type of various functions) is a synonym for “void”, meant to tell the GUI designer that the particular function carries the signature of an action method, i.e. it’s a void function that takes only a “(id)sender” as an argument. These are functions that the Interface Builder can “wire up” to an action: i.e they implement the response to a button click, value change, menu command, etc. Again, marking this function this way tells Interface Builder to let you use drag-and-drop from a menu command (say) to this function in order to have this function implement that menu command.
The .nib or .xib file (two different formats for the same thing) is where all this GUI wiring is hidden, along with things like view layouts and the set of objects available to the system.
The “App Delegate” created for you is primarily just a place for you to do initialization and shutdown: implement applicationDidFinishLaunching: or applicationWillTerminate: You can do other stuff here, more on the Mac than in the iPhone, for last-chance menu handling and the like.
It’ll usually make one or more view controllers and views for you. The views are the visual representation onscreen, for custom ones you can implement drawView: to do the actual drawing of the view. The view controllers are for initialization, placement, and relocation of the views, along with things like handling what happens when the screen rotates.
There will also be a main.m or main.mm file (Obj-C and Obj-C++, respectively) that contains the main() function, which you usually never have to touch (initialization should happen in the App Delegate).
My friend and I are still learning. It’s kind of been at the back of the shelf what with layoffs, moves, new girlfriends, new jobs, courses, exams, etc. But we’re going to do it, honest!
Thanks TimeWinder. I’ve book marked this page for when I get back to programing. Since my wife has taken over the iPad for good, I’ll have to get my own.
I have a very work relevant app I want to write. Ironically, for all of the complaints about Apples closed architecture, it only works precisely because of it.
By the way, if anybody here wants to write apps that will work on an Iphone without using a Mac, check out NS Basic/App Studio. I took part in the Beta-test group, though I didn’t really have time to get into it as much as I wanted yet. It’s an IDE that produces HTML5/Javascript pages that can be imported to run locally as apps.
And they’ll run on Iphone/Ipad/Droid! (Plus Blackberry 5 I believe.)
It is a video podcast of the Stanford lectures, complete with homework assignments, available for free via iTunes University. Grab them while you can—there are no promises as to how long a particular set of lectures will remain available.