我試圖用一個複合謂詞來使用Cloudkit來做到這一點,但Xcode錯誤說「意外的表達」。任何人都知道我的代碼有什麼問題?感謝任何幫助!NSCompoundPredicate和Cloudkit
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)
我不明白爲什麼這些謂詞會失敗。你能包括你得到的確切的錯誤嗎? – farktronix 2015-04-01 16:54:37
CKRecordIDs是否有postID和followIDs的CKReferences數組? – Marcus 2015-10-26 21:59:19
@馬庫斯。那些數組是recordID,我正在查詢這些recordID的元數據索引。 userRef變量是一個CKReference。 – 2015-10-26 22:54:26