How to invoke completion block in CloudKit in Swift 2 in iOS 9?

488 Views Asked by At

I did not managed to translate my working iOS8 code snippet into iOS 9 Swift 2 Xcode version 7.0 beta (7A120f).

My last attempt was:

saveRecordsOperation.perRecordCompletionBlock {
    (record:CKRecord, recordID:CKRecordID, error:NSError) -> Void in

    print("perRecordCompletionBlock \(record)")
}

But Xcode says:

AppDelegate.swift:929:34: Cannot invoke 'perRecordCompletionBlock' with an argument list of type '((CKRecord, CKRecordID, NSError) -> Void)'

Any idea?

1

There are 1 best solutions below

2
On BEST ANSWER

Ok, here is the solution:

       saveRecordsOperation.perRecordCompletionBlock = {
            (record:CKRecord?, error:NSError?) -> Void in

            print("perRecordCompletionBlock \(record)")
        }

There where two issues actually: one I introduced while dealing around to find a solution when I desperately added recordID, while the second was we now must use equal sign to pass the code block.

Hope it helps.