iTunes API 写得不好。您必须使用谓词过滤数组。
NSArray *allSongs = [self allSongs];
NSArray *songsOfAlbum = [allSongs filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"album == %@ && artist == %@", albumString, artistString]];
你可以得到所有这样的歌曲:
// Get all Songs
- (NSArray *)allSongs {
if (_allSongs == nil) {
NSArray *tracksToPlay = [(SBElementArray *)[self.library tracks] get];
// Sort by artist
_allSongs = tracksToPlay;
}
return _allSongs;
}
- (iTunesLibraryPlaylist *)library {
if (_library == nil) {
// Whole Library
iTunesSource *source = [[[[self.iTunes sources] get] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"kind == %i", iTunesESrcLibrary]] objectAtIndex:0];
// Only the Music
_library = [[[[source playlists] get] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"specialKind == %i", iTunesESpKMusic]] objectAtIndex:0];
}
return _library;
}