November 2013
Beginner
325 pages
9h 47m
English
Before a literal syntax was introduced for creating instances of NSArray, developers used the class method arrayWithObjects:.
// Create an array containing three pointers (nil terminates the list)
NSArray *dateList = [NSArray arrayWithObjects:now, tomorrow, yesterday, nil];
The nil at the end tells the method to stop. Thus, this date array has three objects. (If you forget the nil, it will probably crash your program, but you will at least get a compiler warning.)
The syntax that you used to access items in the dateList array is known as subscripting. Before subscripting was introduced, developers used the objectAtIndex: method to access an item in an array:
// Print a couple of dates NSLog(@"The ...
Read now
Unlock full access