Contents

SHMediaItem

An object that represents the metadata for a reference signature.

Declaration

class SHMediaItem

Overview

This class uses subscripting for the data elements of a custom media item that an existing property doesn’t already represent.

Add a readable custom property by extending SHMediaItemProperty with a key for that property, and by extending this class with a property that uses the key. The following code shows the extensions for an episode number:

// Add an episode number to the list of properties.
extension SHMediaItemProperty {
    static let episode = SHMediaItemProperty("Episode")
}

// Add a property for returning the episode number using a subscript.
extension SHMediaItem {
    var episode: Int? {
        return self[.episode] as? Int
    }
}

Add your custom property when you create the media item as the following code shows:

// Create a new media item and set the title, subtitle, and episode properties.
let mediaItem = SHMediaItem(properties: [.episode: 42,
                                         .title: "Question",
                                         .subtitle: "The Answer"])

Topics

Creating a new media item object

Working with media item properties

Reading general media item properties

Reading Apple Music properties

Working with Shazam music catalog media items

Initializers

Default Implementations

See Also

Match audio