Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data & Xcode 11: Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer

Just moved to Xcode 11 and getting the following crash at launch:

CoreData: fault: One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName. Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead. At some point, Core Data will default to using "NSSecureUnarchiveFromData" when nil is specified, and transformable properties containing classes that do not support NSSecureCoding will become unreadable.

CoreData: warning: Property 'color' on Entity 'Group' is using nil or an insecure NSValueTransformer. Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead.

I'm creating an NSPersistentContainer at launch using the code below:

private let container: NSPersistentContainer = {     let container = NSPersistentContainer(name: "MyApp", managedObjectModel: MyAppModelVersion.current.managedObjectModel())     let storeDescription = NSPersistentStoreDescription(url: getStoreURLWithUserName())     storeDescription.shouldMigrateStoreAutomatically = true     storeDescription.shouldInferMappingModelAutomatically = true     container.persistentStoreDescriptions = [storeDescription]     return container }() 

Error occurs right after this line is executed:

let container = NSPersistentContainer(name: "MyApp", managedObjectModel: MyAppModelVersion.current.managedObjectModel()) 

I also have a property called 'Colorin aGroup` entity that's transformable:

@NSManaged public var color: UIColor? @NSManaged public var hexColorValue: String? 

Below is how set the property:

public var hexColor: String? {     get {         return self.hexColorValue     }     set {         self.hexColorValue = newValue         if let str = newValue {             self.color = UIColor(hex: str)         }     } } 

This is what the property looks like in Core Data:

enter image description here

I am not sure how to recover from this crash. This was working fine with Xcode 10

like image 235
user1107173 Avatar asked Sep 22 '19 20:09

user1107173


People also ask

What is meant by Core Data?

Core Data is a framework that you use to manage the model layer objects in your application. It provides generalized and automated solutions to common tasks associated with object life cycle and object graph management, including persistence.

Is Core Data a database?

Core Data is not a database. Core Data is a framework for managing an object graph. An object graph is nothing more than a collection of interconnected objects. The framework excels at managing complex object graphs.

What is meant by Core Data in Swift?

Getting Started Core Data (CRUD) with Swift. Core Data is a graphical and persistence framework, which is used in Apple devices with operating systems macOS and iOS. Core Data was first introduced in Mac OS X 10.4 Tiger and iOS with iPhone SDK 3.0.


2 Answers

Setting Transformer property to NSSecureUnarchiveFromDataTransformer solved the warning in my case. For this select the attribute & set its transformer type to NSSecureUnarchiveFromDataTransformer & run again by pressing commond+R.

Thanks, Ratneshwar

like image 156
Ratneshwar Singh Avatar answered Sep 21 '22 10:09

Ratneshwar Singh


Swift 5.4.2

This worked for me.

EDIT Link to the article is here.

  • Click on the .xcdatamodeld file in the project navigator
  • Click on the Entity that has a Transformable Attribute
  • Click on the Transformable Attribute
  • Click the 'Show Data Model Inspector' icon
  • Enter 'NSSecureUnarchiveFromDataTransformer' in the Transformer field - EDIT Make this 'NSSecureUnarchiveFromData' as of Swift 5.5.2.

Your warnings/errors should go away. If not, try cleaning your build folder and rebuild.

like image 38
SouthernYankee65 Avatar answered Sep 19 '22 10:09

SouthernYankee65