EntityIdentifier
A type that uniquely identifies a specific instance of an app entity.
Declaration
struct EntityIdentifierOverview
The value used should be unique across all entities of the given type. Entities which are relevant across executions of the application should have stable identifiers that persist across executions.
Entities, by default, conform to the Identifiable protocol. Use a type for the id that conforms to EntityIdentifierConvertible. Default implementations for String, UUID and Int are provided.
For example:
struct Song: AppEntity {
let id = UUID()
}Cross-Device Stable Identifiers
For entities that adopt SyncableEntity, the framework automatically extracts stable identifiers for cross-device session syncing:
Passthrough case: If your entity’s ID is already stable across devices (like server UUIDs), just adopt SyncableEntity with no other changes. The framework uses your ID as both the local and stable identifier.
Mapped case: If your entity has different local and stable identifiers, use SyncableEntityIdentifier as your ID type. The framework extracts the stable ID from the wrapper.
Apps never interact with EntityIdentifier.stableIdentifier directly - they work with their entity’s ID type (plain types like UUID, or SyncableEntityIdentifier for mapped IDs).
The stable identifier is NOT used for equality or hashing - two EntityIdentifier instances are equal if they have the same type and local identifier, regardless of stable identifier value.