Apple stock is falling on the news that iPhone 5 sales are expected to be down 40% below projections. Without Steve Jobs at the helm, it was only a matter of time before this sort of thing happened.
It seems like a great time for me to finally get started learning IOS development. One part of the impetus comes from my work at Ancestry.com where I’m working to development better software testing practices — which happens to include for IOS. And the other part comes from my own project (currently on hold) to develop a mobile app.
I feel like I’m getting a late start in IOS development, but that’s OK. There have been some good developments lately that make it much easier including storyboards, automatic memory management, and UIAutomation. Which are great, but there is still a lot of code out there that doesn’t take advantage of it all, and much of the information you’ll find online is out of date.
I’ll try to address this and would appreciate any comments that can correct me.
First off, you’ll need a Macintosh computer. Apple has decreed that you need to use their tools (and while there are ways around it — like the aforementioned Sencha Touch, Titanium Appcelerator, Xamarin, etc. — they’re still not as mature and are all proprietary.)
And then you’ll need XCode. That’s the Apple IDE. It’s kindof ok. Not a great productivity booster, but at least it’s free now. Download it from the app store (iTunes). That’s right, Apple thinks a software development platform is an MP3.
I’m going to start with a simple Hello world to get you up and running in IOS. And then I’m going to build an adventure game based on a popular movie franchise.
I’m using XCode 4.5 (which is quite different from XCode 4-4.2 which is a total change from XCode 3) so screenshots and UI directions might get quickly out of date.
Once you’ve installed XCode, create a new project, and since we’re doing this for iPhone app-love let’s create an IOS application.
From the toolbar click “File -> New -> Project”. Choose an application template. IOS -> Application -> Single View Application (we’re not too ambitious.)
Enter your project information and click next.
Take a look at your project in XCode and notice the files on the left hand side
You have the the folling files:
The .h files are interface files (think “like C headers” but not too hard.)
The .m files are implementation files (think “like .c files” but not really.)
The .storyboard is your user interface.
Click on MainStroyboard_iPhone.storyboard and it brings up the Interface Builder. Which shows a picture of an iPhone screen.
Look in the lower right corder. You see “Objects” with “View Controller” highlighed. Remember selecting “Single View” in the template. This is what you get. Another common View Controller is the “Table View Controller” and I’ll let you guess what that does. A basic ViewController is what we have SWViewController is it.
You can see it the source code by clicking on SWViewController.m and if you click on the toolbar: View -> Assistant Editor -> Show Assistant Editor or click on the theater mask (shirt with bowtie?) in the upper right corner of your screen you’ll see SWViewController.h right alongside it.
Let’s just ignore the details of Objective-C for now. I don’t get it, and I’m going to explain it a in a little more detail in my next post. As far as I’m concerned Objective-C is esthetically the most objectionable programming language I’ve ever seen. And that includes a nightmare hybrid of Perl and BASIC.
But we want to see this thing do something, and compile, and run. So go back to your storyboard and where it says “Objects” in the lower right corner, click the dropdown and change it to “Controls”
Then click and drag a label onto the storyboard.
Change your label to say something interesting (not by doubleclicking) by clicking on the label, then clicking on the 4th icon in the top right (a seatbelt?) and editing the field under Text: Plain where it says “Label” to say something more interesting:
Expand the label by dragging, and tweak the font size and color to your heart’s content. Come back when you’re done playing and then select “IPhone 6.0 Simulator” under “IOS Device” in the top left corner of XCode and click Run. After a couple minutes you’ll see first cool new iPhone app.
Congratulations. You’ve taken your first step into a larger world.