17 NSArray

NSArray is another commonly used Objective-C class. An instance of NSArray holds a list of pointers to other objects.

Create a new project: a Foundation Command Line Tool called DateList. This program will create an array that holds a list of pointers to NSDate objects.

Creating arrays

Open main.m and change main():

#​i​m​p​o​r​t​ ​<​F​o​u​n​d​a​t​i​o​n​/​F​o​u​n​d​a​t​i​o​n​.​h​>​

i​n​t​ ​m​a​i​n​(​i​n​t​ ​a​r​g​c​,​ ​c​o​n​s​t​ ​c​h​a​r​ ​*​ ​a​r​g​v​[​]​)​
{​
 ​ ​ ​ ​@​a​u​t​o​r​e​l​e​a​s​e​p​o​o​l​ ​{​

 ​ ​ ​ ​ ​ ​ ​ ​/​/​ ​C​r​e​a​t​e​ ​t​h​r​e​e​ ​N​S​D​a​t​e​ ​o​b​j​e​c​t​s​ ​ ​ ​ ​ ​ ​ ​ ​N​S​D​a​t​e​ ​*​n​o​w​ ​=​ ​[​N​S​D​a​t​e​ ​d​a​t​e​]​;​ ​ ​ ​ ​ ​ ​ ​ ​N​S​D​a​t​e​ ​*​t​o​m​o​r​r​o​w​ ​=​ ...

Get Objective-C Programming: The Big Nerd Ranch Guide 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.