[英]CloudKit : CKQuery showing error: error: The operation couldn’t be completed. (CKErrorDomain error 1.)
I working on iOS app implementing cloudkit but I need to query all the records with ID greater then a number. 我正在开发实现cloudkit的iOS应用,但是我需要查询ID大于数字的所有记录。 For example I have record with ID of 23:
例如,我有ID为23的记录:
here is my code: 这是我的代码:
CKContainer *myContainer = [CKContainer containerWithIdentifier:containerID];
CKDatabase *publicDatabase = [myContainer publicCloudDatabase];
CKRecordID *recordID = [[CKRecordID alloc] initWithRecordName:@"23"];
CKReference* recordToMatch = [[CKReference alloc] initWithRecordID:recordID action:CKReferenceActionNone];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"recordID >= %@", recordToMatch];
CKQuery *query = [[CKQuery alloc] initWithRecordType:recordType predicate:predicate];
[publicDatabase performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error) {
if (error) {
NSLog(@"error: %@", error.localizedDescription);
}
else {
}
}];
But I'm getting the following error: 但我收到以下错误:
error: error: The operation couldn't be completed. 错误:错误:操作无法完成。 (CKErrorDomain error 1.)
(CKErrorDomain错误1。)
Any of you knows how can I setup my NSPredicate in a way where I can get all the records with ID greater then 23 ? 你们谁都知道如何设置NSPredicate的方式来获取ID大于23的所有记录?
I'll really appreciate your help. 非常感谢您的帮助。
For a query like this you could use a predicate like: 对于这样的查询,您可以使用如下谓词:
in Swift: 在Swift中:
var predicate = NSPredicate(format: "recordID >= %@", CKRecordID(recordName: "23"))
In Objective C: 在目标C中:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"recordID >= %@", [CKRecordID initWithRecordName:@"23"]];
Then I do assume that you created the CKRecords object originally while specifying this number. 然后,我确实假定您在指定此数字时最初创建了CKRecords对象。 Otherwise recordID values will be assigned by CloudKit and will be a GUID.
否则,recordID值将由CloudKit分配,并将为GUID。
Your recordID of 23 is stored as a CKRecordID type and not as a number thus you cannot use any numeric predicates like greater-than. 您的recordID为23是作为CKRecordID类型而不是数字存储的,因此您不能使用任何数字谓词,例如大于。 You should create a new number field in your record for storing your integer IDs and query that instead.
您应该在记录中创建一个新的数字字段,以存储您的整数ID并对其进行查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.