How to fetch next batch of albums for an Artist?

Hello,

I am fetching and displaying the .fullalbums for an Artist through the MusicKit api.

The JSON response returned has a hasNextBatch: true value, but I am unsure how to fetch and display the next batch.

Is this something that can be intelligently retrieved though some MusicKit functionality or does one have to perform another data request to fetch the next batch?

Replies

Hello @ashinthetray,

Once you have an Artist with .fullAlbums loaded (let's assume it's stored in a variable named artist), you can very simply access the next batch of items using MusicItemCollection's hasNextBatch and nextBatch():

if let fullAlbums = artist.fullAlbums {
    print("fullAlbums = \(fullAlbums)")
    
    if fullAlbums.hasNextBatch {
        if let fullAlbumsNextBatch = try await fullAlbums.nextBatch() {
            print("fullAlbumsNextBatch = \(fullAlbumsNextBatch)")
        }
    }
}

I hope this helps.

Best regards,

@JoeKun Mind-blown! Thanks again for your reply, you are a rockstar.