Last active
December 16, 2015 22:39
-
-
Save matthewmayer/5508346 to your computer and use it in GitHub Desktop.
objective-c shortcuts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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