Contents

EntityIdentifierConvertible

An interface for converting between an entity’s identifier and its string representation.

Declaration

protocol EntityIdentifierConvertible

Mentioned in

Overview

Every entity provides a stable, unique identifier that the framework uses as a concrete reference to the entity while mediating between your app and other parts of the system. To enforce this requirement, the AppEntity protocol inherits the Identifiable protocol.

Wherever possible, use String, Int, or UUID for an identifier’s type. If you must use a different data type, use this protocol to extend that type and implement the required support. For example, an app that integrates with the MusicKit framework might use MusicItemID as the type for an entity’s identifier.

extension MusicItemID: EntityIdentifierConvertible {
    public var entityIdentifierString: String {
        rawValue
    }

    public init?(entityIdentifierString: String) {
        self = MusicItemID(entityIdentifierString)
    }
}

Topics

Creating an identifier string

Getting the identifier string

See Also

Entity identity