我尝试使用Cloudkit使用复合谓词来实现此目的,但Xcode错误显示为“意外表达式”。有人知道我的代码出了什么问题吗?感谢您的帮助!
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)发布于 2015-04-01 03:42:15
在CloudKit中使用NSPredicate有一些规则。有关更多信息,请参阅Apple documentation
您可以尝试像这样创建谓词:
NSPredicate(format: "recordID IN %@ OR (recordID IN %@ AND user = %@)", followIDs, postIDs, userRef)但是我在使用带有AND和OR语句的谓词方面有不好的经验。如果这个谓词不起作用,那么我认为唯一的解决方案是执行两个单独的查询,然后组合结果。您可以通过使用ExSwift库中的联合函数来完成此操作
https://stackoverflow.com/questions/29376315
复制相似问题