Using MusicItemID

I have two questions related to the id for Playlist and Song.

(1) There are two properties named id in each type. One is defined to be a MusicItemID and one is an ObjectIdentifier. How does one distinguish between them? What is the difference in how we are two use them.

(2) Suppose the user has built a custom playlist of Song items in my app. Should I persist the MusicItemID and then retrieve the Song later using a MusicCatalogResourceRequest?

It's a fun API to play with but there's little documentation.

Thank you,

Daniel

Hello @dimsumthinking,

The id property typed as ObjectIdentifier doesn't actually exist for items in MusicKit. The presence of this entry in our documentation is actually due to some sort of issue in the documentation generation toolchain. Feel free to file a ticket on Feedback Assistant so we can escalate that to the documentation tools team.

As for your second question, you can definitely persist the MusicItemID of one or more instances of Song and then load them again using MusicCatalogResourceRequest. You can even use MusicCatalogResourceRequest's init(matching:memberOf:) to load multiple songs with a single request.

Another option is to leverage the fact that Song conforms to Codable. So you can also choose to persist an entire collection of songs, and then decode them right back. This allows you to retrieve the list of songs without requiring a network request.

I hope this helps.

Best regards,

Using MusicItemID
 
 
Q