Obtaining a lists of artists using cocoalibspotify

2020-03-30 06:07发布

问题:

I'd like to quickly get a list of artist names in a user's "library" or playlists. Is there an easy / asynchronous way to do this?

回答1:

Take a look at the example project "Guess the Intro" included with CocoaLibSpotify. The method waitAndFillTrackPool in that project shows how to get a list of all the tracks in the user's playlists.

Once you have that list, you can do the following to get the artists from them, put them through a set to thin out duplicates, then wait until they're loaded.

NSArray *artists = [theTrackPool valueForKeyPath:@"@unionOfArrays.artists"];
NSArray *uniqueArtists = [[NSSet setWithArray:artists] allObjects];

[SPAsyncLoading waitUntilLoaded:uniqueArtists then:^(NSArray *loadedArtists) {
    // Artists are loaded!
    // Log a list of artist names...
    NSLog(@"%@", [loadedArtists valueForKey:@"name"]);
}];