Newbie Questions,
I have 3 Class , 3 of them are subclass of NSObject
a. Collection Class
This class will have 2 property
- masterSongs (Contains all songs) declared as NSMUtableSet (copy, nonatomic)
- listofPlaylists (contains all playlists) declared as NSMutableArray (copy, nonatomic)
b. Playlist Class
This Class will have 2 property
- playListName declared as NSString
- songLists declared as NSMutableArray (strong, nonatomic), only store reference to the song not copy of song.
c. Songs Class
This Class has 4 property declared as NSString :
- title
- artist
- playingtime
- album
Questions :
- I want to create removeSong method for Collection class, so when I delete particular song from Collection (masterSongs), it will also delete song in all of playList stored in Collection.listofPlaylists. but I am stuck with syntaxes*.
*I am using lookup method to create a NSSet and then using that set to remove song object from NSMutableSet masterSongs using - minusSet: method
also, I found that it's dangerous to change modify NSMutableSet while enumerating on it.
here I tried so far :
- (NSSet *) lookUpTitle: (NSString *)aName {
NSPredicate *filter = [NSPredicate predicateWithFormat:@"title == %@",aName];
NSSet *result = [self.masterSongs filteredSetUsingPredicate:filter];
if ([result count] == 0) {
NSLog(@"not found");
return nil;
}
else{
return result;
}
}
- (void) removeSong: (NSString *)zSong{
for (Song *aSong in masterSongs) {
if ([self lookUpTitle:zSong] != nil) {
NSMutableSet *container = [NSMutableSet setWithSet:self.masterSongs];
}
}
}
- (void) addSong :(Song *)aSong{
if (![masterSongs containsObject:aSong]) {
[masterSongs addObject:aSong];
} }
-(void) addPlaylist: (Playlist *)aPlayList{
if ([listOfPlaylists containsObject:aPlayList]==YES) {
}
else
[listOfPlaylists addObject:aPlayList];
}
-(void) removePlaylist: (Playlist *)aPlayList{
if ([listOfPlaylists containsObject:aPlayList]) {
[listOfPlaylists removeObjectIdenticalTo:aPlayList];
}
else{
;
}
}