CloudKit - NSPredicate for finding all records that contain specified CKReference in a reference list

前端 未结 2 579
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-06 16:21

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 foll

相关标签:
2条回答
  • 2021-02-06 16:43

    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.

    0 讨论(0)
  • 2021-02-06 16:48

    Error 11 means that the query cannot find any items in your container matching your record type. In your case UserRecordType type records do not exist in Cloud Kit. You can create a sample schema for that type and the query will work after that.

    0 讨论(0)
提交回复
热议问题