I am doing a full transition of an app from CoreData to SwiftData. I was able to follow the online guides and extract SwiftData objects from the CoreData model. Everything seems to work except for my Transformable String Arrays. This app is storing CoreData in iCloud.
In my SwiftData model, I have a variable...
@Attribute(.transformable(by: "NSSecureUnarchiveFromData"))
var arrayofStrings: [String]?
The app is able to read the array of strings, however, the debugger gives me this error eventually crashing due to memory.
'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
I don't understand, the transformed variable already is 'NSSecureUnarchiveFromData' not 'NSKeyedUnarchiveFromData'. That's the reason why I used NSSecureUnarchiveFromData in my CoreData model because NSKeyedUnarchiveFromData is being phased out. I don't get why the debugger thinks otherwise.
Any thoughts?
Ok, I think I figured it out. So.. when you generate SwiftData Objects from Core Data and if you have Transformable Data like above what I've done with an Array of Strings, you will get
@Attribute(.transformable(by: "NSSecureUnarchiveFromData"))
var yourArrayOfStrings: [String]?
However, SwiftData is so good that it already recognizes these Array of Strings so having that Attribute confuses Xcode to thinking you're using NSKeyedUnarchiveFromData. The solution is to just delete that attribute like so...
var yourArrayOfStrings: [String]?
And it just works! The warning goes away in the Debugger.