有人知道如何在 CloudKit 中使用子查询吗?这是我的尝试代码:
// stringArray is String list in Cloudkit
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(stringArray, $fS, ANY $fS = %@).@count != 0", targetString];
CKQuery *query = [[CKQuery alloc] initWithRecordType:@"TestRecord" predicate:predicate];
[publicDatabase performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error) {
NSLog(@"%@", results);
}];
但捕获到 CKException 并显示失败消息 Expected key-path in comparison expression: SUBQUERY(stringArray, $fS, ANY $fS = "targetString").@count != 0
有什么想法或有什么问题吗?
最佳答案
查看有关 NSPredicates for CloudKit 的文档。 https://developer.apple.com/library/ios/documentation/CloudKit/Reference/CKQuery_class/index.html#//apple_ref/swift/cl/CKQuery
如您所见,它只允许您为完整的 NSPredicate 类执行的操作的一个子集。子查询和聚合(如 .@count)是不允许的。
关于ios - 在 Cloudkit 中使用子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27587339/