CoreData:错误 - 实体不是符合键值编码的ID

时间:2016-04-23 18:20:48

标签: ios xcode swift core-data

我有核心数据错误,当我尝试保存 组<< - >>之间的关系时接触

我通过 hashUser 从coredata获取一个联系人,并通过 uid 获取一个Group 并尝试使用func

添加关系 to-many
// extension CXDMContact
func addGroup(value: CXDMGroup) {
    let items = self.mutableSetValueForKey("groups");
    items.addObject(value)
}

当我尝试保存它时,我得到了exeption

CoreData: error: Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  [<CXDMGroup 0x7fb7924aa770> valueForUndefinedKey:]: the entity Group is not key value coding-compliant for the key "id". with userInfo {
    NSTargetObjectUserInfoKey = "<CXDMGroup: 0x7fb7924aa770> (entity: Group; id: 0xd0000000000c0000 <x-coredata://E66299CB-12A5-4152-8B49-8E9B3B68762F/Group/p3> ; data: {\n    contacts =     (\n        \"0xd000000000040002 <x-coredata://E66299CB-12A5-4152-8B49-8E9B3B68762F/Contact/p1>\"\n    );\n    uid = 5;\n})";
    NSUnknownUserInfoKey = id;
}

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<CXDMGroup 0x7fb7924aa770> valueForUndefinedKey:]: the entity Group is not key value coding-compliant for the key "id".'

但我没有任何 ID 字段,如果我现在查看managedObjectContext,我会看到

(lldb) po managedObjectContext.updatedObjects
▿ 2 elements
  - [0] : <CXDMContact: 0x7fb7927f5270> (entity: Contact; id: 0xd000000000040002 <x-coredata://E66299CB-12A5-4152-8B49-8E9B3B68762F/Contact/p1> ; data: {
    chatStatus = nil;
    companyId = nil;
    companyName = OWN;
    companySubscription = nil;
    connectedLoads = nil;
    countryCode2 = nil;
    departmentName = nil;
    email = nil;
    firstname = Ownname;
    groups =     (
        "0xd0000000000c0000 <x-coredata://E66299CB-12A5-4152-8B49-8E9B3B68762F/Group/p3>"
    );
    jobTitle = nil;
    lastname = Lastname;
    messages = "<relationship fault: 0x7fb7924a25b0 'messages'>";
    phone1 = nil;
    phone2 = nil;
    serialNumber = nil;
    status = Offline;
    timeZoneName = nil;
    userHash = 1002;
})
  - [1] : <CXDMGroup: 0x7fb7924aa770> (entity: Group; id: 0xd0000000000c0000 <x-coredata://E66299CB-12A5-4152-8B49-8E9B3B68762F/Group/p3> ; data: {
    contacts =     (
        "0xd000000000040002 <x-coredata://E66299CB-12A5-4152-8B49-8E9B3B68762F/Contact/p1>"
    );
    uid = 5;
})

(lldb) po managedObjectContext.insertedObjects
0 elements

(lldb) po managedObjectContext.deletedObjects
0 elements

我不明白钥匙“id”在哪里? 请帮忙

2 个答案:

答案 0 :(得分:5)

正如错误提示的那样,这个问题与观察上下文保存的事情有关。如果您使用NSFetchedResultsController或监视该事件的其他内容,那么那里就会出现问题。也许是UITableViewCell中某处的拼写错误?

答案 1 :(得分:0)

在控制器的某个地方寻找尝试设置或获取id而不是uid的事件。