I am migrating a CloudKit-synchronized multi-platform app from CoreData to SwiftData. (Xcode 27.0 beta 5).
One of my Models/Entities contains a Transformable attribute, which is defined in the CoreData model editor as:
and which is defined in the generated CoreData class as
@NSManaged nonisolated public var authorNames: [String]?
Using the built-in translation took, Xcode created a Model wich included
@Attribute(.transformable(by: "NSSecureUnarchiveFromDataTransformerName")) var authorNames: [String] = []
This compiles but does not run. In the function
func getModelContainer() throws -> ModelContainer {
let storeURL = try FileManager.default.url(
for: .applicationSupportDirectory,
in: .userDomainMask,
appropriateFor: nil, create: true)
.appendingPathComponent(dbName)
let modelConfiguration = ModelConfiguration(
schema: dbSchema, url: storeURL,
cloudKitDatabase: .automatic)
let container = try ModelContainer(
for: dbSchema,
migrationPlan: MigrationPlan.self,
configurations: [modelConfiguration])
return container
}
the app throws a fatal error in the ModelContainer initializer,
SwiftData/SchemaCoreData.swift:398: Fatal error: Application must register a ValueTransformer for NSSecureUnarchiveFromDataTransformerName
So I added the following line of code at the top of this function:
ValueTransformer.setValueTransformer(
NSSecureUnarchiveFromDataTransformer(),
forName: .secureUnarchiveFromDataTransformerName)
which also compiles but also throws the same fatal error in the same place.
Can anyone suggest how to resolve this problem? This is a CloudKit synchronized app, so I am constrained in what I can do with this attribute.
1
0
32