【问题标题】:CKQuery where predicate has reference and not field?CKQuery 谓词有引用而不是字段?
【发布时间】:2014-07-25 17:57:32
【问题描述】:

我需要创建一个CKQuery,其中谓词包含对记录的引用,而不是记录的字段。

这样

let query = CKQuery(recordType: "OUP", predicate: NSPredicate(format: "o = %@", "FF4FB4A9-271A-4AF4-B02C-722ABF25BF44")

如何设置o 是 CKReference,而不是字段!

我收到此错误:

字段“o”的查询谓词中的字段值类型不匹配

【问题讨论】:

    标签: cloudkit ckquery


    【解决方案1】:

    您可以使用带有或不带有 CKReferenceCKRecordCKRecordID 来匹配关系。

    CK 记录:

    let predicate = NSPredicate(format: "artist == %@", artist)
    

    CKRecordID:

    let predicate = NSPredicate(format: "artist == %@", artistID)
    

    带有 CKRecord 的 CKReference:

    let recordToMatch = CKReference(record: artist, action: CKReferenceAction.None)
    let predicate = NSPredicate(format: "artist == %@", recordToMatch)
    

    带有 CKRecordID 的 CKReference:

    let recordToMatch = CKReference(recordID: artistID, action: CKReferenceAction.None)
    let predicate = NSPredicate(format: "artist == %@", recordToMatch)
    

    【讨论】:

      【解决方案2】:

      我在CKQuery class reference 中找到了答案,或者至少在CKQuery 中找到了如何使用CKReference 的示例:

      CKReference* recordToMatch = [[CKReference alloc] initWithRecordID:employeeID action:CKReferenceActionNone];
      NSPredicate* predicate = [NSPredicate predicateWithFormat:@"employee == %@", recordToMatch];
      

      要匹配链接到您知道其 ID 的不同记录的记录,请创建一个谓词来匹配包含引用对象的字段,如清单 1 所示。在示例中,记录的员工字段包含指向的 CKReference 对象到另一个记录。执行查询时,如果本地创建的 CKReference 对象中的 ID 与记录的指定字段中找到的 ID 相同,则会发生匹配。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-08-28
        • 1970-01-01
        • 1970-01-01
        • 2017-07-15
        • 2017-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多