2015-10-12 50 views
0

我想製作一個雲工具包nspredicate,它將返回所有項目,其中forSale(Int)== 1和ownerRecord(CKRefereance)!=當前用戶的記錄。 以下是我有:NSPredicate CKReference不是用戶ID

let Query = CKQuery(recordType: "Item", predicate: NSPredicate(format: "ownerRecord.recordID != %@, forSale = 1", [NSUserDefaults.standardUserDefaults().objectForKey("cloudkitUserReccordID") as! String])) 

回答

0

您需要查詢的引用而不是一個字符串的recordId。你然後才能將類似於:

let ownerId = NSUserDefaults.standardUserDefaults().objectForKey("cloudkitUserReccordID") as! String 
let ownerRef = CKReference(recordID: CKRecordID(recordName: ownerId), action: CKReferenceAction.None) 
let predicate = NSPredicate(format: "ownerRecord != %@, forSale = 1", ownerRef) 
let query = CKQuery(recordType: "Item", predicate: predicate)) 
+0

似乎這劑量不工作,***終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因:「無法解析格式字符串「ownerRecord =%@,可供出售= 1「' –