当我想从私人数据库中获取记录时,它会向我显示以下错误:
传递给CKFetchRecordsOperation的意外recordID:CKReference:0x7fb691c1c300; 8BBDA567-D00A-4603-91A2-D436677F3952:(_ defaultZone:__ defaultOwner __)
我不知道为什么。我从之前提取的记录中获取了记录ID,并参考了“所有者”记录。所以我想从我的引用属性中获取recordID。
我做错了什么?
这是我的代码:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"creationDate > %@", upToDate];
CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Car" predicate:predicate];
CKContainer *container = [CKContainer defaultContainer];
CKDatabase *privateDB = [container privateCloudDatabase];
[privateDB performQuery:query inZoneWithID:nil completionHandler:^(NSArray*results, NSError*error){
for (CKRecord*carRecord in results) {
CarModel *car = [CarModel new];
CKRecordID *ownerID = [record objectForKey:@"owner"];
[privateDB fetchRecordWithID:ownerID completionHandler:^(CKRecord *record, NSError*error){
// here i expect record with recordID same as recordID in my reference attribute
}
奇怪的是,当我在仪表板中搜索时,我的错误消息中的8BBDA567-D00A-4603-91A2-D436677F3952是正确的ID。
有其他方法可以获取“所有者”记录吗?
答案 0 :(得分:1)
您的ownerID应为CKReference类型。然后你必须像这样查询ownerID.recordID:
CKReference *ownerID = [record objectForKey:@"owner"];
[privateDB fetchRecordWithID:ownerID.recordID completionHandler:^(CKRecord *record, NSError*error){