SyncableEntityIdentifier
A type-safe wrapper you use to specify different local and stable identifiers for an entity.
Declaration
struct SyncableEntityIdentifier<LocalID, StableID> where LocalID : EntityIdentifierConvertible, LocalID : Sendable, StableID : EntityIdentifierConvertible, StableID : SendableMentioned in
Overview
Use this structure if you maintain separate local and stable identifiers in one of your entity types. Assign this structure to the id property of your entity and use the value in the local property to refer to the entity in your code. The system uses the stable value to refer to the same entity during operations that occur on another device.
When referring to an entity in your code, you can refer to this type directly. The following example shows an entity that uses this type for its identifier. The query object for the entity similarly refers to this type directly in methods.
struct Photo: AppEntity, SyncableEntity {
var id: SyncableEntityIdentifier<String, String>
var creationDate: Date
}
struct PhotoQuery: EntityQuery {
func entities(for ids: [SyncableEntityIdentifier<String, String>]) async throws -> [Photo] {
// Works everywhere - queries, entities, helper functions
}
}For additional information about how to use this type, see SyncableEntity.