Home Tutorial Iphone Examples Objective C Array

 
 

Share on Google+Share on Google+
Objective C Array
Posted on: October 6, 2010 at 12:00 AM
Advertisement
In a simple term we can say that array is a object, which is a collection of number of other objects. In Objective C, we can also add and remove the objects from the given list of array if the array is declared mutable.

Objective C Array

In a simple term we can say that array is a object, which is a collection of number of other objects. In Objective C, we can also add and remove the objects from the given list of array if the array is declared mutable.

Syntax to declare an Array in Objective C:

NSArray *myArray
or
NSMutableArray *myMutableArray

You can declare an array either in header file (.h) or in implementaion file (.m) at the time of implementation.

Declaring an Array at the time of implementation

NSArray *myArray;
myArray = [NSArray arrayWithObjects: @"Red", @"Green", @"Blue", @"Yellow", nil];

or Mutable Array like:

NSMutableArray *myMutableArray;
myMutableArray = [NSArray arrayWithObjects: @"Red", @"Green", @"Blue", @"Yellow", nil];

We can also add or insert more objects in an array even after declaring it if it is a mutable array… for example

"addObject" in an array

NSMutableArray *myMutableArray;
myMutableArray = [NSArray arrayWithObjects: @"Red", @"Green", @"Blue", @"Yellow", nil];
[myMutableArray addObject:@"Orange"];
[myMutableArray addObject:@"Black"];

"insertObject" in an array

NSMutableArray *myMutableArray;
myMutableArray = [NSArray arrayWithObjects: @"Red", @"Green", @"Blue", @"Yellow", nil];
[myMutableArray insertObject:@"Orange" atIndex: 2];
[myMutableArray insertObject:@"Black" atIndex: 5];

and so on…

Advertisement

Related Tags for Objective C Array:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 6, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com