Migrating from CoreData to SwiftData causes crashes on Watch app

I'm working on migrating my app from using CoreData to SwiftData. The swift data code generated by Xcode works correctly for the iOS and Mac Catalyst targets but it is causing a crash for the WatchOS target.

It gives me this message **Fatal error: Application must register a ValueTransformer for NSSecureUnarchiveFromDataTransformer **

This attribute is the only one with a .transformable option.

@Attribute(.transformable(by: "NSSecureUnarchiveFromDataTransformer")) 
public var linkedEntities: [UUID] = []

Changing the string NSSecureUnarchiveFromDataTransformer to NSValueTransformerName.secureUnarchiveFromDataTransformerName.rawValue causes a generic crash with no error message.

The app has CloudKit integration as well (not sure if relevant).

Does anyone have a similar issue and can help me on what to do here?

Replies

If this was a custom transformer, I would say you need to add ValueTransformer.setValueTransformer(NSSecureUnarchiveFromDataTransformer(), forName: NSValueTransformerName("NSSecureUnarchiveFromDataTransformer")) in your app's init(), but AFAIK UUID is Codable so I'm not sure you need a transformer here. Have you tried just ditching @Attribute(.transformable(by: "NSSecureUnarchiveFromDataTransformer"))?

Taking it out worked but I have a worst problem where the SwiftData never syncs to the watch or to the iMessage app. I haven't had time to work on this project lately to try to pinpoint what is causing the issue 😓