首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSCompoundPredicate和Cloudkit

NSCompoundPredicate和Cloudkit
EN

Stack Overflow用户
提问于 2015-04-01 02:54:55
回答 1查看 1.3K关注 0票数 3

我尝试使用Cloudkit使用复合谓词来实现此目的,但Xcode错误显示为“意外表达式”。有人知道我的代码出了什么问题吗?感谢您的帮助!

代码语言:javascript
复制
let userRef = CKReference(recordID: userID, action: .None)

    let predicateOne = NSPredicate(format: "recordID IN %@ AND user = %@", postIDs, userRef)
// I need all user post's that match the IDs in the array and where the user ID matches the Id in the reference field for the user.

    let predicateTwo = NSPredicate(format: "recordID IN %@", followIDs)
// Or I want recordID's that match the IDs in this array.
// I want records if either predicate condition is met, or both, which is why I'm using an OrPredicateType.

    let predicate = NSCompoundPredicate(type: NSCompoundPredicateType.OrPredicateType, subpredicates: [predicateOne!, predicateTwo!])
    let query = CKQuery(recordType: "UserPosts", predicate: predicate)
    let queryOp = CKQueryOperation(query: query)
EN

回答 1

Stack Overflow用户

发布于 2015-04-01 03:42:15

在CloudKit中使用NSPredicate有一些规则。有关更多信息,请参阅Apple documentation

您可以尝试像这样创建谓词:

代码语言:javascript
复制
NSPredicate(format: "recordID IN %@ OR (recordID IN %@ AND user = %@)", followIDs, postIDs, userRef)

但是我在使用带有AND和OR语句的谓词方面有不好的经验。如果这个谓词不起作用,那么我认为唯一的解决方案是执行两个单独的查询,然后组合结果。您可以通过使用ExSwift库中的联合函数来完成此操作

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29376315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档