Skip to content

Instantly share code, notes, and snippets.

@arod2634
Last active Aug 29, 2015
Embed
What would you like to do?
Looping though an NSMutableArray
NSMutableArray *myParty = [[NSMutableArray alloc] init];
[myParty addObject:@"Name: Alex's Awesome Party"];
[myParty addObject:@"Address: 123 Awesome Street"];
[myParty addObject:@"Date: May 17"];
// Manually output the value in each index
NSLog(@"%@",[myParty objectAtIndex:0]);
NSLog(@"%@",[myParty objectAtIndex:1]);
NSLog(@"%@",[myParty objectAtIndex:2]);
// Loop though array in with a traditional for loop
for (int i = 0; i < [myParty count]; i++) {
NSLog(@"%@", myParty[i]);
}
// Loop though array using fast enumeration
for (id detail in myParty) {
NSLog(@"%@", detail);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment