CoreData crash error Xcode 11 Beta, IOS 13 Beta CoreData crash error Xcode 11 Beta, IOS 13 Beta swift swift

CoreData crash error Xcode 11 Beta, IOS 13 Beta


I found this solution. The errors have disappeared and it would seem to work. I keep testing.

For all Transformable attributes, I have set “Transformer” to “NSSecureUnarchiveFromData” in the Data Model Inspector panel.

enter image description here

EDIT:

After a few days of testing I add something to my previous solution.

The previous solution works if, after the changes, the application is deleted. Otherwise, the data model is not recognized and is created from scratch, losing all the historical information (and in production this is not acceptable!!!).

The final solution I adopted was to add these changes to a new model (following this link) and implementing the migration (always described in the link).

In this case the warning appears only once after the update and then disappears.


My solution was to stay with old default transformers in order to avoid any compatibility issues. The issues may arise since default (nil) transformers will be replaced with NSSecureUnarchiveFromData eventually, I'm not sure if previously persisted values would be decoded properly (they were encoded by default transformer but after the update they will be decoded by NSSecureUnarchiveFromDataTransformer). I've implemented an explicit default transformer for fields of NSDictionary, NSArray, NSSet foundation types that comply to NSCoding out of the box:

@objc(DefaultTransformer)class DefaultTransformer: ValueTransformer {    override class func transformedValueClass() -> AnyClass {        return NSData.self    }    override open func reverseTransformedValue(_ value: Any?) -> Any? {        guard let value = value as? Data else {            return nil        }        return NSKeyedUnarchiver.unarchiveObject(with: value)    }    override class func allowsReverseTransformation() -> Bool {        return true    }    override func transformedValue(_ value: Any?) -> Any? {        guard let value = value else {            return nil        }        return NSKeyedArchiver.archivedData(withRootObject: value)    }}

For my special datatypes that comply NSCoding I've implemented particular transformers as follows:

@objc(EmailTransformer)class EmailTransformer: ValueTransformer {    override class func transformedValueClass() -> AnyClass {        return NSData.self    }    override open func reverseTransformedValue(_ value: Any?) -> Any? {        guard let value = value as? Data else {            return nil        }        return NSKeyedUnarchiver.unarchiveObject(with: value)    }    override class func allowsReverseTransformation() -> Bool {        return true    }    override func transformedValue(_ value: Any?) -> Any? {        guard let value = value as? [Email] else {            return nil        }        return NSKeyedArchiver.archivedData(withRootObject: value)    }}

After that, I set these transformers for the transformable fields, thus explicitly opted the safest way. Pros of the solution: you don't need to bother with data migration, just implement explicit transformers and set them to any data model version you already have.