我必须 CKOperations 并想在第一次操作完成后开始第二次操作。我如何“告诉”第二次手术等到第二次手术完成?
这是我的第一个操作(创建自定义区域):
let operation = CKModifyRecordZonesOperation(recordZonesToSave: customZone, recordZoneIDsToDelete: nil)
operation.modifyRecordZonesCompletionBlock = { (savedRecordZones, deletedRecordZonse, error) in
if error != nil {
//Creation Failed
print("Cloud Error\n\(error?.localizedDescription)")
} else {
// Zone creation succeeded
print("The 'CompanyZone' was successfully created in the private database.")
}
}
privateDatabase.add(operation)
这是我的第二次操作(存储记录):
let operation = CKModifyRecordsOperation(recordsToSave: companyRecords, recordIDsToDelete: nil)
operation.modifyRecordsCompletionBlock = { (savedRecords, deletedRecordIDs, error) in
if error != nil {
print("Cloud Error\n\(error?.localizedDescription)")
} else {
print("Record saved successfully in the custom zone called, Company")
}
// savedRecords is an array of saved CKRecords
// deletedRecordIDs is an array of the CKRecordIDs for the deleted records
}
privateDatabase.add(operation)