How can I only retrieve playlists that are editable? Or in other words how can I retrieve playlists that are only created by the user?
We can get the playlists of the user by the following code block:
var request = MusicLibraryRequest<Playlist>()
request.sort(by: \.lastPlayedDate, ascending: false)
let response = try await request.response()
Also, we can add a track to the playlist with the following code block:
TASK {
do {
try await MusicLibrary.shared.add(track, to: playlist)
} catch (let error) {
print(error)
}
}
However not all playlists are editable. For instance if the playlist created by Apple or another Apple Music user, we receive an error while adding track to the playlist because we don't have a permission to do it.
I receive the following error:
Error Domain=MPErrorDomain Code=5 "The requested action is not supported" UserInfo={NSLocalizedDescription=The requested action is not supported}
I haven't figured out how to do with the new
MusicLibraryRequestso I wrote my own implementation. Hope it helps.The first step is to create a
MLibraryPlaylistthat has thecanEditproperty, because that's what you want:Then, fetch the library playlists using the Apple Music API and decode the data as a collection of
MLibraryPlaylistinstead ofPlaylist:I hope it solves your problem! I know it is not as good as the native implementation where you can also filter by the last played date.