Skip to content

Instantly share code, notes, and snippets.

@arod2634
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arod2634/9360274 to your computer and use it in GitHub Desktop.
Save arod2634/9360274 to your computer and use it in GitHub Desktop.
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