我收到这个核心数据错误。我不知道为什么会出现此错误。我没有使用任何可转换类型。我在代码中看不到任何内容表明我正在使用可转换属性。我让 Xcode 在创建项目时通过选择"使用核心数据"选项来设置 CoreData。其他类似的问题也无济于事,因为答案与代码有关,这些代码看起来像我在创建项目时可以找到的 Xcode 创建的任何内容。当此错误出现在调试窗口中时,项目不会崩溃。我使用的是 Xcode 11.3 和 iOS 版 Google Maps SDK for iOS 12,它运行在装有 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)
}
我想你可能忽略了一个名为"GMSCacheProperty"的实体。
如错误消息中所述:
CoreData:警告:实体"GMSCacheProperty"上的属性"值"正在使用 nil 或不安全的 NSValueTransformer。
此实体具有使用 nil 或不安全的 NSValueTransformer 的属性"值"。
当我使用自己的代码而不是removeFromAddresses(_ value: Address(从Route.addresses中删除地址时,我发现我做错了什么。当我使用 removeFromAddresses(_ value: Address( 而不是我自己的代码修复我的代码时,有问题的错误消息消失了。