the codemonky

ramblings, musing and code snippets from shawn veader
Jan 07
Permalink

Obj-C Oddities

I never seem to find enough time to be in Obj-C land long enough to develop muscle memory so there are things that consistently get me. NSDictionary creation is backwards:

NSDictionary *stuff = 
[NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", 
                                           @"value2", @"key2", nil];
In Ruby-land (where I’ve been for quite some time) it would be:
stuff = { :key1 => "value1", :key2 => "value2" }
Almost forgot! I also almost always forget the nil at the end of an NSDictionary or NSArray declaration. For instance:
NSArray *myList = [NSArray arrayWithObjects: @"foo", @"bar", @"baz", nil];
I continually forget that trailing nil, but it should be obvious since C is under the covers after all.