There's a few modern features of Objective C you should be using in new code, if not existing code. They make code easier to write and improve readability.
- Forward function declarations for "private" functions aren't needed anymore.
-
Use container and
NSNumber
literals:NSNumber num = @{1.2}; NSArray a1 = @[@"one", @"two"]; NSMutableArray a2 = [NSMutableArray arrayWithArray:@[@"one", @"two"]]; NSDictionary d1 = @{@"key1": @"value1", @"key2": @"value2"}; NSMutableDictionary* d2 = [NSMutableDictionary dictionaryWithDictionary:d1];
-
Use container subscripting:
NSArray a1 = @"[@"one", @"two"]; NSString one = a1[0]; NSDictionary d1 = @{@"key1": @"value1", @"key2": @"value2"}; NSString val = d1[@"key2"];
In Xcode, you can use Edit > Convert > To Modern Objective-C Syntax to help you update existing code.
Your feedback is valuable: Do you want more nuggets like this? Yes or No
.