iOS 6 PTL: Chapter 2 Errata

We made a typo in Chapter 2, section Collection Literals.

The syntax for creating a new NSDictionary was written as

NSDictionary *dict = @[@"key1":@"value1", @"key2":@"value2", @"key2":@"value2"]

The correct syntax is

NSDictionary *dict = @{

Curly braces are used for creating dictionaries and square brackets are used for creating arrays.

In Object Subscripting section,
when you access a element in an array using a subscript, you get a NSNumber

So the correct code that compiles without a warning is as below.

NSArray *array = @[@1, @2, @3, @4, @5]
NSNumber *elementAt3 = array[3];

Thanks to Luca Bernardi for pointing this out.


Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>