O'Reilly logo

Programming in Objective-C, Sixth Edition by Stephen G. Kochan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required