In this year's WWDC2012, we introduced the new Objc syntax. It's really nice to use and the code is simple and clear, just like the script language.
NSArray
Previously, an array was initialized like this.
NSArray * array = [NSArray arrayWithObjects: a, B, c, nil];
The new method is
NSArray * array = @ [a, B, c];
[Array objectAtIndex: 1] the corresponding new method is array [1].
NSDictionary
Previously, a dictionary was initialized like this.
NSDictionary * dict = [NSDictionary dictionaryWithObjects: @ [o1, o2, o3]
ForKeys: @ [k1, k2, k3];
The new method is as follows:
NSDictionary * dict =@{ k1: o1, k2: o2, k3: o3 };
Id obj = [dict objectForKey: @ "1"] the corresponding new method is id obj = dict [@ "1"]
Here @ "1" is NSString or NSNumber still to be studied.
NSNumber
The previous implementation was as follows:
NSNumber * number;
Number = [NSNumber numberWithChar: 'X'];
Number = [NSNumber numberWithInt: 12345];
Number = [NSNumber numberWithUnsignedLong: 12345ul];
Number = [NSNumber numberWithLongLong: 12345ll];
Number = [NSNumber numberWithFloat: 123.45f];
Number = [NSNumber numberWithDouble: 123.45];
Number = [NSNumber numberWithBool: YES];
The new method is as follows:
NSNumber * number;
Number = @ 'X ';
Number = @ 12345;
Number = @ 12345ul;
Number = @ 12345ll;
Number = @ 123.45f;
Number = @ 123.45;
Number = @ YES;
How does it feel? Is it getting better and better?