CloudKit saveRecord完成

时间:2015-08-31 00:43:27

标签: ios swift icloud cloudkit ckquery

我正在使用以下代码更新记录。记录更新后,我想运行我的刷新功能。目前,在更新记录之前有时会调用刷新功能,因此刷新结果与记录更新前的结果相同。

由于

var tempDocumentsArray:NSArray!
let recordID = CKRecordID(recordName: "layerAbove")
var predicate = NSPredicate(format: "recordID = %@", recordID)
let query = CKQuery(recordType: "Layers", predicate: predicate)
self.publicDB.performQuery(query, inZoneWithID: nil) { (results, error) -> Void in
tempDocumentsArray = results
print("Results are: \(tempDocumentsArray)")
let record = tempDocumentsArray[0] as! CKRecord

var layerAbovePrevPos = record.objectForKey("layerNumber") as! Int
layerAbovePrevPos = layerAbovePrevPos - 1
let nlnChanged = record.setObject(layerAbovePrevPos, forKey: "layerNumber")

self.publicDB.saveRecord(record, completionHandler: { (returnRecord, error) -> Void in
    if let err = error {
        print("Error: \(err.localizedDescription)")
    } else {
        dispatch_async(dispatch_get_main_queue()) {
            print("Success")


            //TODO:This is sometimes called before the save is complete!
            self.resetAndGet()


        }
    }
})
}

0 个答案:

没有答案