核心数据错误切换到使用“NSSecureUnarchiveFromData”或 NSSecureUnarchiveFromDataTransformer 的子类

Posted

技术标签:

【中文标题】核心数据错误切换到使用“NSSecureUnarchiveFromData”或 NSSecureUnarchiveFromDataTransformer 的子类【英文标题】:Core Data error switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead 【发布时间】:2020-01-13 19:12:16 【问题描述】:

我收到此 CoreData 错误。我不知道为什么会收到此错误。我没有使用任何可转换类型。我在我的代码中看不到任何东西表明我正在使用可转换的属性。在创建项目时,我通过选择 Use Core Data 选项让 Xcode 设置 CoreData。其他类似的问题没有帮助,因为答案与我能找到的任何在创建项目时创建的 Xcode 的代码有关。当此错误出现在调试窗口中时,项目不会崩溃。我正在为 ios 12 使用 Xcode 11.3 和适用于 iOS 的 Google Maps SDK,它在装有 iOS 13.3 的 iPhone 8 设备上运行。

CoreData: annotation:  Failed to load optimized model at path '/var/containers/Bundle/Application/A2B8A56C-E0D5-467A-9300-8EDFB20574BE/Routes.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileProto.omo'
2020-01-13 12:42:00.771883-0600 Routes[4631:1067373] [error] 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: 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.
2020-01-13 12:42:00.771972-0600 Routes[4631:1067373] [error] CoreData: 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 'value' on Entity 'GMSCacheProperty' is using nil or an insecure NSValueTransformer.  Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead.
CoreData: annotation:  Failed to load optimized model at path '/var/containers/Bundle/Application/A2B8A56C-E0D5-467A-9300-8EDFB20574BE/Routes.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileProto.omo'
CoreData: warning: Property 'value' on Entity 'GMSCacheProperty' is using nil or an insecure NSValueTransformer.  Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead.
CoreData: annotation:  Failed to load optimized model at path '/var/containers/Bundle/Application/A2B8A56C-E0D5-467A-9300-8EDFB20574BE/Routes.app/GoogleMaps.bundle/GMSCacheStorage.momd/StorageWithTileProto.omo'
CoreData: warning: Property 'value' on Entity 'GMSCacheProperty' is using nil or an insecure NSValueTransformer.  Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead.

这是触发错误的代码:

do 

    storeAddresses = try managedObjectContext.fetch(Address.fetchRequest())

 catch 

    print(error)


我正在使用以下核心数据对象:

地址实体

位置属性

输入整数 16

文本属性类型字符串

时间戳属性类型日期

路由关系目的地路由反向地址

路由实体

时间戳属性类型日期

标题属性类型字符串

地址关系目标地址反向路由

我有以下托管对象类的代码:

public class Address: NSManagedObject 



extension Address 

    @nonobjc public class func fetchRequest() -> NSFetchRequest<Address> 
        return NSFetchRequest<Address>(entityName: "Address")
    

    @NSManaged public var text: String?
    @NSManaged public var timestamp: NSDate
    @NSManaged public var position: Int16
    @NSManaged public var route: Route?



public class Route: NSManagedObject 



extension Route 

    @nonobjc public class func fetchRequest() -> NSFetchRequest<Route> 
        return NSFetchRequest<Route>(entityName: "Route")
    

    @NSManaged public var timestamp: NSDate
    @NSManaged public var title: String?
    @NSManaged public var addresses: NSSet?



// MARK: Generated accessors for addresses
extension Route 

    @objc(addAddressesObject:)
    @NSManaged public func addToAddresses(_ value: Address)

    @objc(removeAddressesObject:)
    @NSManaged public func removeFromAddresses(_ value: Address)

    @objc(addAddresses:)
    @NSManaged public func addToAddresses(_ values: NSSet)

    @objc(removeAddresses:)
    @NSManaged public func removeFromAddresses(_ values: NSSet)


【问题讨论】:

【参考方案1】:

我认为您可能忽略了一个名为“GMSCacheProperty”的实体。

如错误信息中所述:

CoreData:警告:实体“GMSCacheProperty”上的属性“值”正在使用 nil 或不安全的 NSValueTransformer。

这个实体有一个使用 nil 或不安全的 NSValueTransformer 的属性“值”。

【讨论】:

【参考方案2】:

当我使用自己的代码而不是 removeFromAddresses(_ value: Address) 从 Route.addresses 中删除地址时,我发现我做错了。当我使用 removeFromAddresses(_ value: Address) 而不是我自己的代码来修复我的代码时,有问题的错误消息消失了。

【讨论】:

以上是关于核心数据错误切换到使用“NSSecureUnarchiveFromData”或 NSSecureUnarchiveFromDataTransformer 的子类的主要内容,如果未能解决你的问题,请参考以下文章

将美国切换到核心数据

核心数据实体多种构建配置

如何在 sqlite 核心数据文件之间正确切换?

在选项卡之间切换时获取核心数据

SwiftUI - 如何切换核心数据中的所有布尔值

swiper5切换页面数据动态加载