Skip to content

Instantly share code, notes, and snippets.

@matthewmayer
Last active December 16, 2015 22:39
Show Gist options
  • Save matthewmayer/5508346 to your computer and use it in GitHub Desktop.
Save matthewmayer/5508346 to your computer and use it in GitHub Desktop.
objective-c shortcuts
//ok
[an_array objectAtIndex:i]
//better
an_array[i]
//ok
[dict objectForKey:@"foo"]
//better
dict[@"foo"]
//ok
[NSDictionary dictionaryWithObjectsAndKeys:obj1,@"key1",obj2,"key2",nil]
//better
@{@"key1":obj1,@"key2":obj2} //notice the @ before the {
//ok
[NSArray arrayWithObjects:obj1,obj2,nil]
//better
@[obj1,obj2]
//ok
[NSNumber numberWithInt:num]
//better "boxing"
@(num)
//ok
[NSNumber numberWithFloat:2.3f]
//better
@(2.3f)
//ok
for (id btn in buttonArray) {}
//better, assuming you know the class of the objects in the array
for (UIButton *btn in buttonArray) {}
//ok
[arr objectAtIndex:(arr.count-1)]
//better
[arr lastObject]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment