Home Iphone NSMutableArray example
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

NSMutableArray example

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

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];
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


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 4, 2013

Related Tutorials

Ask Questions?    Discuss: NSMutableArray example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com