CHAPTER 8

image

Arrays

NSArray

NSArray is a class used to organize objects in lists. NSArray can maintain an index of objects, search for objects, and enumerate through the list. Enumeration is the process of moving through a list one item at a time and performing an action on each item in the list.

To create an array, you include a comma-separate list of objects enclosed in square brackets and started with the @ symbol.

NSArray *numbers = @[@-2, @-1, @0, @1, @2];NSArray *letters = @[@"A", @"B", @"C", @"D", @"E", @"F"];

The NSArray object numbers has a list of NSNumber objects, while letters has a list of strings. Any object can be put into an NSArray ...

Get Objective-C Quick Syntax Reference 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.