CloudKit – 用于在引用列表中查找包含指定CKReference的所有记录的NSPredicate

我正在使用具有“跟随”引用列表属性的用户记录类型的CloudKit支持的应用程序。 我正在尝试构建一个查询以获取跟随指定用户的每个用户(即指定用户在以下引用列表中显示为条目的那些用户)。

我目前正在尝试为NSPredicate构建我的NSPredicate

 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%@ IN following", [[CKReference alloc] initWithRecordID:currentUserID action:CKReferenceActionNone]]; CKQuery *query = [[CKQuery alloc] initWithRecordType:UserRecordType predicate:predicate]; 

并且CloudKit返回以下错误消息:

 "Unknown Item" (11/2003); server message = "did not find required record type"; 

我觉得我的谓词中可能会遗漏一些相当直接的东西。 任何帮助将不胜感激!

使用CONTAINS运算符测试列表成员资格:

 CKReference* recordToMatch = [[CKReference alloc] initWithRecordID:currentUserID action:CKReferenceActionNone]; NSPredicate* predicate = [NSPredicate predicateWithFormat:@"following CONTAINS %@", recordToMatch]; 

如果要查询多个引用,则需要为列表中的每个引用使用带有AND谓词类型的复合谓词。

错误11表示查询无法在容器中找到与记录类型匹配的任何项目。 在您的情况下,Cloud Kit中不存在UserRecordType类型记录。 您可以为该类型创建示例模式,然后查询将起作用。