CloudKit CKOperation Queue

539 views Asked by At

I have to CKOperations and want to start the 2nd one after the 1st operation finishes. How can I "tell" the 2nd operation to wait until the 2nd one is finished?

This is my first operation (create custom zone):

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)

And here is my second operation (store record):

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)
0

There are 0 answers