Instance Method

getPlaylist(with:creationMetadata:completionHandler:)

Retrieves an app maintained existing playlist or creates a new playlist when no playlist exists.

Declaration

func getPlaylist(with uuid: UUID, creationMetadata: MPMediaPlaylistCreationMetadata?, completionHandler: @escaping (MPMediaPlaylist?, Error?) -> Void)

Parameters

uuid

The unique identifier for the playlist.

creationMetadata

The metadata used when a new playlist is created. When a playlist already exists, this parameter is ignored.

completionHandler

A block that is called after the playlist has been retrieved or created.

playlist

Contains the playlist identified by the UUID or the newly created playlist.

error

If an error occurred, this parameter holds the error object that explains the error. Otherwise, the value of this parameter is nil.

Discussion

This function retrieves the playlist associated with the UUID. Create a static instance of the UUID using a previously generated UUID. Creating a new UUID using init(uuidString:) to retrieve a playlist does not guarantee that the playlist will be retrieved.

When there is no playlist associated with the UUID, a new playlist is created with the UUID and the creation metadata. The creation metadata parameter is ignored when the playlist already exists.