gpt4 book ai didi

ios - +[同步更改 :inEntityNamed:predicate:parent:inContext:dataStack:completion:] 中的断言失败

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:56:51 25 4
gpt4 key购买 nike

我正在使用 Sync from HyperOslo我得到一个简单的 JSON 对象:

打印的 json 对象(用户)=>

[{
email = "email@email.fr";
name = "Damian Menestrel";
}]

...使用以下方法在 Core Data User 中转换:

Sync.changes(user , inEntityNamed: "User", dataStack: DataManager.dataStack, completion: { (response ) -> Void in

})

应用程序崩溃并出现此错误:

Assertion failure in +[Sync changes:inEntityNamed:predicate:parent:inContext:dataStack:completion:], .../Pods/Sync/Source/Sync.m:77

这个错误从何而来?


我的 CodeData 模型是:

enter image description here

用户.swift

import Foundation
import CoreData
import UIKit

class User: NSManagedObject {
@NSManaged var email: String?
@NSManaged var name: String?
}

最佳答案

简答:只需将 remoteID 属性添加到您的 Core Data 模型作为主键,它就可以工作。这将映射到您的 JSON 中的 id 属性。

长答案:

取自Primary Key Sync 的自述文件部分。

Sync requires your entities to have a primary key, this is important for diffing otherwise Sync doesn’t know how to differentiate between entries.

By default Sync uses id from the JSON and remoteID from Core Data as the primary key. You can mark any attribute as primary key by adding hyper.isPrimaryKey and the value YES.

For example in our Designer News project we have a Comment entity that uses body as the primary key.

Custom primary key

关于ios - +[同步更改 :inEntityNamed:predicate:parent:inContext:dataStack:completion:] 中的断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33397102/

25 4 0