iosswiftswift3aws-sdkawss3transfermanager

Ambigous use of `continue` after upgrading from Swift 2.2 to Swift 3.0


I have a swift project and I'm using there Amazon Web Services.

I have a function responsible for uploading image to my S3 bucket, in Swift 2.2 it worked well and the code was as follows:

let credentialsProvider = AWSCognitoCredentialsProvider(regionType:CognitoRegionType,
                                                            identityPoolId:CognitoIdentityPoolId)
    let configuration = AWSServiceConfiguration(region:CognitoRegionType, credentialsProvider:credentialsProvider)
    AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration



let uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest.body = NSURL(string: "file://"+pathToFile)
uploadRequest.key = NSProcessInfo.processInfo().globallyUniqueString + "." + ext
uploadRequest.bucket = S3BucketName
uploadRequest.contentType = contentType + ext

let transferManager = AWSS3TransferManager.defaultS3TransferManager()
    transferManager.upload(uploadRequest).continueWithBlock { (task) -> AnyObject! in

        if (task.completed) {
        ...

Now, after upgrading to Swift 3, I have:

let credentialsProvider = AWSCognitoCredentialsProvider(regionType:CognitoRegionType,
                                                            identityPoolId:CognitoIdentityPoolId)
    let configuration = AWSServiceConfiguration(region:CognitoRegionType, credentialsProvider:credentialsProvider)
    AWSServiceManager.default().defaultServiceConfiguration = configuration



let uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest?.body = URL(string: "file://"+pathToFile)
uploadRequest?.key = ProcessInfo.processInfo.globallyUniqueString + "." + ext
uploadRequest?.bucket = S3BucketName
uploadRequest?.contentType = contentType + ext

let transferManager = AWSS3TransferManager.default()
    transferManager?.upload(uploadRequest).continueWithBlock { (task) -> AnyObject! in

        if (task.isCompleted) {

Now in the last statement transferManager?.upload(uploadRequest).continueWithBlock throws an error that says

'continueWithBlock' has been renamed to 'continue(_:)'

so I follow their advices and change it to:

transferManager?.upload(uploadRequest).continue { 

but then it throws me an error:

Ambigous use of continue

Available methods are here:

enter image description here

but I'm not sure which one could I use in this case. Can you help me with that?


Solution

  • Ok I found the issue, it was easier than I thought... It was mentioned here: https://github.com/aws/aws-sdk-ios/issues/473 and said to change the

    transferManager?.upload(uploadRequest).continue { ... }
    

    to

    transferManager?.upload(uploadRequest).continue ({ ... })
    

    Method naming in this case is indeed annoying, but it works.