Objective-C literals for NSDictionary, NSArray, and NSNumber

Objective-C literals: one can now create literals for NSArray, NSDictionary, and NSNumber (just like one can create literals for NSString)

NSArray Literals

Previously:

 array = [NSArray arrayWithObjects:a, b, c, nil];

Now:

array = @[ a, b, c ];

NSDictionary Literals

Previously:

dict = [NSDictionary dictionaryWithObjects:@[o1, o2, o3]

  forKeys:@[k1, k2, k3]];

Now:

dict = @{ k1 : o1, k2 : o2, k3 : o3 };

NSNumber Literals

Previously:

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];

Now:

NSNumber *number;

number = @'X';

number = @12345;

number = @12345ul;

number = @12345ll;

number = @123.45f;

number = @123.45;

number = @YES;

  1. chan9118kin reblogged this from cocoaheads
  2. mcdecoste reblogged this from cocoaheads
  3. ricardofalasca reblogged this from cocoaheads
  4. iosadam reblogged this from cocoaheads
  5. amirmemon reblogged this from cocoaheads
  6. musiccodewine reblogged this from cocoaheads and added:
    A little while ago, I said I was going to take a wait and see approach with these literals. Well, with a new project...
  7. artbgz reblogged this from cocoaheads and added:
    I don’t know how I can live without this (|l|O_o)
  8. alexvinidiktov reblogged this from cocoaheads
  9. ania-springer reblogged this from cocoaheads
  10. mackmac reblogged this from cocoaheads
  11. halsk reblogged this from cocoaheads
  12. jdrama418 reblogged this from cocoaheads
  13. wonwon-pierce reblogged this from cocoaheads
  14. smokyonion reblogged this from cocoaheads
  15. kennygunie reblogged this from cocoaheads
  16. amirsaam reblogged this from cocoaheads
  17. seapomeranian reblogged this from cocoaheads