Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize an empty mutable array in Objective C

Tags:

I have a list of objects (trucks) with various attributes that populate a tableview. When you tap them they go to an individual truck page. There is an add button which will add them to the favorite list in another tableview. How do I initialize an empty mutable array in Cocoa?

I have the following code:

-(IBAction)addTruckToFavorites:(id)sender:(FavoritesViewController *)controller {     [controller.listOfTrucks addObject: ((Truck_Tracker_AppAppDelegate *)[UIApplication sharedApplication].delegate).selectedTruck];  } 
like image 595
crashprophet Avatar asked Apr 19 '12 08:04

crashprophet


1 Answers

Update:

With new syntax you can use:

NSMutableArray *myArray = [NSMutableArray new]; 

Original answer:

for example:

NSMutableArray *myArray = [[NSMutableArray alloc] init]; 

And here you find out why (difference between class and instance method)

like image 62
Jakub Avatar answered Oct 12 '22 00:10

Jakub