Convert to Modern Objective-C Syntax

I thought I’d give this a roll. So, in Xcode I ran it from Edit > Refactor.

Pleasantly surprised at how straightforwards it was.

Quick reminder:

Arrays:

@[@"a String"] == [NSArray arrayWithObject:@"a String"]

arrayOfObjects[i] ==  [arrayOfObjects objectAtIndex:i]

Dictionaries:

key: dictionary[@"SearchResponse"] == [dictionary objectForKey:@"SearchResponse"]

declare: @{@"key": @"object"} == [NSDictionary dictionaryWithObject:@"value" forKey:@"key"]

Numbers:

@1000 == [NSNumber numberWithInt:1000]

The only problems that seem to need looking out for are:

1. relying on early nil termination of arguments when creating an array

2. the need to box BOOL values

http://jamesdempsey.net/2012/07/30/moving-to-new-objective-c-literals/

Leave a Reply

Your email address will not be published. Required fields are marked *