Friday, May 20, 2011

Getting Started With iOS

If you're completely new to programming the iPhone/iPad, know nothing about iOS/xcode, and have never used a MAC, the following might be useful.

Development Platform
Probably the cheapest way to start developing is to buy a Mac Mini. It easily has enough power for xcode. I got mine from carbon computing (2.4GHz 2GB, 320GB, SuperDrive, AirPort, HDMI, GeForce 320M Video). It comes with a power coard and an HDMI to DVI converter. You can plug in your existing DVI monitor and windows USB mouse/keyboard.

Mac Mini

Of course, you probably can't live without two monitors, so you'll need to additionally buy a Mini-DisplayPort to DVI converter. I got this from carbon computing for $40. You can get it from monoprice for $7, but I was in a hurry and don't fully trust knock-offs. I did however buy a usb switch from monoprice for $25 that lets me toggle my keyboard/mouse between the PC/MAC. My monitors have both DVI and VGA out, so I have the DVI cables running to the MAC and the VGA cables running to the PC. To swap the station, you just punch the usb-switch button and the swap buttons on the front of the monitors.

Setting up the MAC OS
Unboxing is easy. Plug it in and hit the power button on the back. It walks you through a friendly first-time-setup. Finder is the magnifying glass at the top-right of your screen. You can use it to search for applications by name, like "update" to find "Software Update". You'll want to run this a few times and update everything. Specifically your OS is probably too old for the latest xcode. Your mac came with some disks, but you don't need these. I also changed my desktop background and customized the dock (the shortcut icons at the bottom of the screen). Just click and drag to remove them (a little dust-cloud icon appears). And drag from finder to the dock to add them.

Even if you're not using a windows keyboard, the change in position of the control-command keys might drive you mad. You can get it to behave more like you're used to by downloading the latest version of doublecommand.

  • [double-click] DoubleCommand-1.6.9.pkg
  • Continue > Continue > Install > [password] OK > Close
  • Eject the installer
  • Finder "DoubleCommand" > System Preferences > DoubleCommand
  • [uncheck] Enter Key acts as Command Key
  • [check] Command Key acts as Control Key
  • [check] Control Key acts as Command Key
  • [check] PC style Home and End keys
  • Click activate button
  • Click system button (and provide password)
  • Close double command

You need to download Xcode. It was free, but the latest version costs $5. If you're serious about development, you'll want to put stuff on the device which requires a $99/year subscription and gives you access to stuff like Xcode. So you might as well start out by enrolling in the Apple Developer Program. Then you download the latest Xcode (which is gigs, and takes a while). Note that Xcode 4 is considerably different than its predecessors, so if you buy any books, make sure they're the new enough. There are a bunch of tutorials and books out there. I'll probably end up posting some sample code here, but for now, I'll just give a list of resources that I found most helpful.

Absolutely Required Reading
iOS Technology Overview -- Cocoa Touch Layer
iOS Technology Overview -- Core Services Layer

Wikipedia on Objective-C
One thing that drove me crazy for a long time was the difference in function naming between C++ and Objective-C. I finally found a good explanation of this on wikipedia.

- (return_type)instanceMethod2WithParameter:(param1_type)param1_varName andOtherParameter:(param2_type)param2_varName;

The named parameter article goes on to explain that function name is actually interleaved with the arguments. In other languages like Ada, this lets you supply arguments in an arbitrary order. Not so with Objective-C. The only purpose for this is to make the code "more readable". So in the above, andOtherParameter is actually part of the function name. Very weird.

Mac OS X Developer Library
The Objective-C Programming Langugage

iOS Developer Library
Using the Quick Look Framework
About Document Interaction

Other Good Stuff
Understanding iOS 4 Backgrounding and Delegate Messaging
This is absolutely essential to understanding your application's life cycle. Read this before you try writing anything from scratch. When a text is guiding you through a sample, you're fine, but when you try to do something original, you'll die without this.

Hot Keys
(Note, I'm assuming you're using DoubleCommand, so I'm substituting CTRL for Command)

CTRL-Shift-3            == capture desktop as png
CTRL-Shift-4            == capture a cross-hair selected portion of the screen as png
CTRL-Shift-4 + Spacebar == capture an application windows as png
{ "loggedin": false, "owner": false, "avatar": "", "render": "nothing", "trackingID": "UA-36983794-1", "description": "Guide for migrating from development on windows to Mac. Examples of simple Objective-C and programming for iOS. Helpful tools on Mac.", "page": { "blogIds": [ 51 ] }, "domain": "", "base": "\/michael", "url": "https:\/\/\/michael\/", "frameworkFiles": "https:\/\/\/michael\/_framework\/_files.4\/", "commonFiles": "https:\/\/\/michael\/_common\/_files.3\/", "mediaFiles": "https:\/\/\/michael\/media\/_files.3\/", "tmdbUrl": "http:\/\/\/", "tmdbPoster": "http:\/\/\/t\/p\/w342" }