Skip to content

Instantly share code, notes, and snippets.

@betawax
Created June 25, 2012 22:49
Show Gist options
  • Save betawax/2991962 to your computer and use it in GitHub Desktop.
Save betawax/2991962 to your computer and use it in GitHub Desktop.
Objective-C Literals
// NSArray Literals
NSArray *array = @[];
NSArray *array = @[@"foo", @"bar", @42];
NSMutableArray *array = [@[] mutableCopy];
// NSDictionary Literals
NSDictionary *dict = @{};
NSDictionary *dict = @{
@"key": @"value",
@42: @"int",
@"float": @3.14f
};
NSMutableDictionary *dict = [@{} mutableCopy];
// NSNumber Literals
NSNumber *number;
number = @23; // numberWithInt
number = @42u; // numberWithUnsignedInt
number = @3.14f; // numberWithFloat
number = @YES; // numberWithBool
// Object Subscripting
NSMutableArray *array = [@[@"foo", @"bar"] mutableCopy];
array[1] = @"foo";
NSMutableDictionary *dict = [@{@"foo": @"bar", @"bar": @"foo"} mutableCopy];
dict[@"foo"] = @"foo";
@betawax
Copy link
Author

betawax commented Jun 25, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment