Use case: I would like to associate subfolders stored in the Application Support Directory
on iOS with already saved instances of a SwiftData
entity type. If I had a way to represent the primary keys of the entities as a string, I could simply name these subfolders after the primary keys (without the need to generate e.g. random UUID folder names and persist these UUIDs as a field in the entity).
The PersistentIdentifier
of SwiftData entities is a Codable
Struct
, which, when encoded with a JSONEncoder
, looks like this:
{
"implementation": {
"uriRepresentation": "x-coredata://StoreID/EntityName/p123",
"isTemporary": false,
"primaryKey": "p123",
"storeIdentifier": "StoreID",
"entityName": "EntityName"
}
}
Is this Codable representation regarded as a part of the public API of SwiftData
, i.e. is it safe to use the primaryKey
field in production in my use case?