NSMutableArray example

Here we have discussed about NSMutableArray and how to add and remove objects in NSMutableArray.

Ads

In this section we will discuss about the NSMutableArray with some examples to clarify its use in programming.

NSMutableArray class adds insert and delete operations to handle array, which it inherits from NSArray. NSMutableArray class declares the interface that maintains a changeable collection of objects.

Why do we need to subclass NSMutableArray?

NSMutableArray class maintain a changeable collection of objects. But when storing the elements of collection or receiving information about collection, custom NSArray object is used.

Example of Creating and and adding object in NSMutableArray:

First create a object of NSMutableArray in the header file

NSMutableArray *array;

//And property
@property(nonatomic, retain)NSMutableArray *array;
in the viewDidLoad method(in implementation file) initialize the array and add objects to it ..as given below.

array = [[NSMutableArray alloc]init]; [array addObject:@"uber uns"]; [array addObject:@"Weiterempfehlen"]; [array addObject:@"App Bewerten"];

Example of creating NSMutablearray, adding objects and then removing all the objects:

NSMutableArray *myArray = [[NSMutableArray alloc] init];
[myArray addObject:@"One"];
[myArray addObject:@"Two"];
[myArray removeAllObjects];
[myArray release];

Advertisements

Share on Google+Share on Google+

NSMutableArray example

Posted on: October 4, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: NSMutableArray example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads