iosswift2xcode7completion-blockckmodifyrecordsoperation

CKModifyRecordsOperation completion Swift 2.0


I have the code below but I am shown an error when building with Xcode 7 and Swift 2.0

The error is Cannot call value non-function type (([CKRecord]?, [CKRecordID]?, NSError?) -> Void)? Thanks

                    let saveRecordsOperation = CKModifyRecordsOperation()

                var ckRecordsArray = [CKRecord]()
                // set values to ckRecordsArray

                saveRecordsOperation.recordsToSave = ckRecordsArray
                saveRecordsOperation.savePolicy = .IfServerRecordUnchanged



                saveRecordsOperation.modifyRecordsCompletionBlock { savedRecords, deletedRecordIDs, error in
                    // deal with conflicts
                    // set completionHandler of wrapper operation if it's the case
                    if saveRecordsOperation.finished == true {

                    }
                }

                database.addOperation(saveRecordsOperation)

Solution

  • saveRecordsOperation.modifyRecordsCompletionBlock { savedRecords, deletedRecordIDs, error in
    

    should be

    saveRecordsOperation.modifyRecordsCompletionBlock = { savedRecords, deletedRecordIDs, error in