Obtaining a lists of artists using cocoalibspotify

2020-03-30 05:30发布

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条回答
闹够了就滚
2楼-- · 2020-03-30 06:00

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"]);
}];
查看更多
登录 后发表回答