-lookUpTitle:
does most of the work for you. It returns a set of songs which need to be removed. You use -minusSet:
to remove them from a NSMutableSet
. To remove the songs from the playlists, you need to loop through your playlists and remove the songs in the set. You use -removeObjectsInArray:
to remove them from a NSMutableArray
.
- (void)removeSong:(NSString *)zSong
{
NSSet *targets = [self lookUpTitle:zSong];
if ([targets count] > 0) {
[self.masterSongs minusSet:targets];
for (Playlist *playlist in self.listOfPlaylists) {
// -allObjects converts the set into an array.
[playlist.songLists removeObjectsInArray:[targets allObjects]];
}
}
}
You asked a new question about properties.
@property (copy) NSMutableSet *masterSongs;
Is a bad idea. A -setMasterSongs:
method is automatically generated which will look something like this:
- (void)setMasterSongs:(NSMutableSet *)masterSongs
{
if (_masterSongs != masterSongs) {
_masterSongs = [masterSongs copy];
}
}
The problem is -[NSMutableSet copy]
returns an NSSet
; similarly, -[NSMutableArray copy]
returns NSArray
. This is why you ran into a problem. NSSet
and NSArray
are immutable, so they don't contain any methods which will change their contents.