Friday, May 6, 2011

NSArray basic examples.

Some basic examples of NSArray class.
How to create an NSArray object.
How to initialized it.
How many elements in it.
How to add an object.
How to get an object at the specified index.




NSMutableArray *array;                                                           //simply defines a mutable Array

array = [[NSMutableArray alloc] init];                                     //saves memory for the Array and initializes it.

arrayCount = [array count];                                      //counts all objects of this array and puts it into the arrayCount variable

[array addObject:[NSNumber numberWithInt:15]];      // appends "15" to the (mutable) array

arrayVariable = [array objectAtIndex:378];            //returns the 379th Object of the array and puts it into arrayVariable