从Swift 2.2升级到Swift 3.0后,不断使用`continue`

时间:2016-10-18 09:00:54

标签: ios swift swift3 aws-sdk awss3transfermanager

我有一个swift项目,我在那里使用亚马逊网络服务。

我有一个函数负责将图像上传到我的S3存储桶,在Swift 2.2中它运行良好,代码如下:

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) {
        ...

现在,升级到Swift 3后,我有:

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) {

现在在最后一个语句中transferManager?.upload(uploadRequest).continueWithBlock会抛出一个错误

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

所以我按照他们的建议将其改为:

transferManager?.upload(uploadRequest).continue { 

然后它给我一个错误:

Ambigous use of continue

可用的方法在这里:

enter image description here

但我不确定在这种情况下我可以使用哪一个。你能帮帮我吗?

1 个答案:

答案 0 :(得分:4)

好的我发现了这个问题,它比我想象的要容易......这里提到过:https://github.com/aws/aws-sdk-ios/issues/473并说要改变

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

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

在这种情况下,方法命名确实很烦人,但它确实有效。