Literals

When Xcode 4.4 was released in July of 2012, the compiler was updated to add support for several new types of literal syntax that make declaring and using NSNumber, NSArray, and NSDictionary much simpler and much more readable. The new syntax follows the lead of NSString literals by using the @ prefix with syntactical elements to define Objective-C objects:

NSString *aString = @"This is a string.";

Now, an @ symbol followed by numbers, brackets, curly braces, or parentheses has special meaning and represents an Objective-C object:

NSNumber *integerNumber = @45;NSArray *workArray = @[aString, floatNumber, integerNumber];NSDictionary *workDict = @{ @"float": floatNumber,                          ...

Get iOS Components and Frameworks: Understanding the Advanced Features of the iOS SDK now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.