Discovering A Crash
I generally create web applications. Things in PHP or Ruby that run for at most a minute, generate a web page, and then terminate. So now that I've picked up iPhone development on the side, there's a lot to remember: pointers, memory management...
For example: let's say I want an array of words. Well, if I were in PHP:
1 $list = array('These', 'Words');
Ruby has a similar construct, but it also makes "give me an array of these words" easier:
1 list = ['these', 'words']
2 # or
3 list = %w(these words)
So how do I do this in ObjC? I thought this worked:
1 list = [[NSMutableArray alloc] initWithObjects:@"These", @"Words"];
But damn was I wrong. It turns out that that will crash your app. What you should be doing is:
1 list = [[NSMutableArray alloc] initWithObjects:@"These", @"Words", nil];
Not ending an NSMutableArray with a nil is apparently frowned upon in polite ObjC society.
And that's your lesson for the day: read the API docs first instead of wasting thirty minutes of your life poring over code wondering where you made a mistake. Like I did.