Trying my hand at the iPhone
I've started working on my first iPhone application - the lure of the "big money" to be made in the AppStore is just too much to resist. Or something like that.
After reading through the docs and looking at some sample apps, I dove in. Within about 20 minutes I was time-warped back to about 1997, back to when I started doing PalmOS development. The docs sucked, were often misleading or flat wrong, and stuff just didn't work like it should. Deja vu. As I have admitted for years, working in Java has spoiled me to systems in which I have to do my own memory management, like the iPhone. Now doing my own memory management I can handle, but I've already wasted hours trying to figure out bugs in which adding a copy to the right spot magically fixed the problem.
For you coders out there, here's a little treat:
NSInteger sorter(id s1, id s2, void *context)
{
NSString* v1=(NSString*)s1;
NSString* v2=(NSString*)s2;
return [v1 compare:v2];
}
- (void)createPicker
{
animationNames = [[[[NSBundle mainBundle] pathsForResourcesOfType:NULL inDirectory:@"animations"] sortedArrayUsingFunction:sorter context:NULL] copy];
CGRect rect = CGRectMake(0.0, 0.0, 320.0, 240.0);
UIPickerView *myPickerView = [[UIPickerView alloc] initWithFrame:rect];
myPickerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES; // note this is default to NO
// add this picker to our view controller, initially hidden
[window addSubview:myPickerView];
[myPickerView release];
}
Notice the copy at the end of the first line of createPicker. Without that, the app bombs. In the debugger, animationNames is fine, but by the time the picker delegate gets invoked it's not if I remove that copy. I still don't get that one, and the other two very much like it, although I'm sure it's something incredibly simple and obvious to someone in the iPhone know.