CloudKit - 用于在引用列表中查找包含指定CKReference的所有记录的NSPredicate [英] CloudKit - NSPredicate for finding all records that contain specified CKReference in a reference list

查看:146
本文介绍了CloudKit - 用于在引用列表中查找包含指定CKReference的所有记录的NSPredicate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



<我正在尝试为 CKQuery 构建我的 NSPredicate

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

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

 未知物品(11/2003); server message =未找到所需的记录类型; 

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

解决方案

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

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

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


I am working on a CloudKit backed app with a Users record type that has a "following" reference list attribute. I am trying to construct a query to get every user that is following a specified user (i.e. those users in which the specified user appears as an entry in the following reference list).

I am currently trying to construct my NSPredicate for the CKQuery as such:

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

And CloudKit returns the following error message:

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

I feel I might be missing something pretty straight forward in my predicate. Any help would be greatly appreciated!

解决方案

Use CONTAINS operator to test list membership:

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

If you want to query for more than 1 reference, then you need to use a compound predicate with AND predicate type for each reference in list.

这篇关于CloudKit - 用于在引用列表中查找包含指定CKReference的所有记录的NSPredicate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆