MehtaiPhoneApps MehtaiPhoneApps - 20 days ago 4x
iOS Question

CompletionHandler Swift 3

I am a bit confused on how to use completion handlers in Swift 3. Previously, in Swift 2.2, I had code like this:

transferUtility.uploadFile(tmpFileURL, bucket: bucket, key: key, contentType: contentType, expression: nil, completionHander: { (task, error) in
self.uploadCompletionHandler(task, transferError: error)

How can I port this to Swift 3?

I get an error that says
Cannot convert value of type '(AWSS3TransferUtilityUploadTask, NSError) -> ()' to expected argument type 'AWSS3TransferUtilityUploadCompletionHandlerBlock?'

Does anyone know what could be wrong?


Check the signature of the AWSS3TransferUtilityUploadCompletionHandlerBlock, now Swift 3 doesn't allow auto type-casting. Swift 3 doesn't allow you to define the completionBlock with different signature, check the ? and ! as well.