NSArray Archives

How to loop through every element in an NSArray

We can use something called Fast Enumeration for this, using a modified for loop: // build an array NSArray *myArray = [[NSArray alloc]initWithObjects:@”One”, @”Two”, @”Three”, @”Four”, nil]; // loop through every element (dynamic typing) for (id tempObject in myArray) { NSLog(@”Single element: %@”, tempObject); } You don’t have to use dynamic typing if you know […]

How to convert an NSArray into an NSMutableArray

There’s a handy function called arrayWithArray that we can use: NSMutableArray *myNewArray = [[NSMutableArray alloc]init]; myNewArray = [NSMutableArray arrayWithArray:myOldArray]; Likewise we can convert a mutable array into a standard one: NSArray *myStandardArray = [[NSArray alloc]init]; myStandardArray = [NSArray arrayWithArray:myMutableArray];