Created
September 8, 2014 04:11
-
-
Save HeidiHansen/372981a592d9b671b848 to your computer and use it in GitHub Desktop.
NSArray Methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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