Array Objects

A Foundation array is an ordered collection of objects. Most often, elements in an array are of one particular type, but that’s not required. Just as there are mutable and immutable strings, there are mutable and immutable arrays. Immutable arrays are handled by the NSArray class, whereas mutable ones are handled by NSMutableArray. The latter is a subclass of the former, which means it inherits its methods.

Program 15.7 sets up an array to store the names of the months of the year and then prints them.

Program 15.7

#import <Foundation/Foundation.h>int main (int argc, char * argv[]){   int    i;   @autoreleasepool {      // Create an array to contain the month names      NSArray  *monthNames = [NSArray  arrayWithObjects: ...

Get Programming in Objective-C, Sixth Edition 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.