简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM