Skip to content

Instantly share code, notes, and snippets.

@HeidiHansen
Created September 8, 2014 04:11
Show Gist options
  • Save HeidiHansen/372981a592d9b671b848 to your computer and use it in GitHub Desktop.
Save HeidiHansen/372981a592d9b671b848 to your computer and use it in GitHub Desktop.
NSArray Methods
- (NSString *)generatePartyList
{
NSMutableArray *partyNamesArray = [[NSMutableArray alloc]init];
for (Person *friend in self.friends){
[partyNamesArray addObject:friend.name];
}
return [partyNamesArray componentsJoinedByString:@", "];
}
- (BOOL)removeFriend:(Person *)friend
{
for (NSInteger i = 0; i < [self.friends count]; i++){
if (self.friends[i] == friend){
[self.friends removeObjectAtIndex:i];
return YES;
}
}
return NO;
}
- (NSArray *)removeFriends:(NSArray *)friends
{
NSMutableArray *result = [[NSMutableArray alloc] init];
for (Person *friend in friends){
[self removeFriend:friend];
[result addObject:friend];
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment