我必须参加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)