【问题标题】:Ambigous use of `continue` after upgrading from Swift 2.2 to Swift 3.0从 Swift 2.2 升级到 Swift 3.0 后,“继续”的模糊使用
【发布时间】:2017-02-27 11:16:00
【问题描述】:

我有一个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

可用的方法在这里:

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

【问题讨论】:

  • continueWithBlock() -> continue(block:)。在 Swift 3 中,xWithY() 变为 x(y:)
  • 我尝试按照您的建议替换它,但错误提示为 AWSTask<AnyObject> has no member continue(block:)...
  • 您是自己将代码转换为 Swift 3,还是来自 AWS lib 开发人员的官方代码?如果不是你的转换,你应该联系 lib 开发人员解决这个问题,如果你的转换是你的,你仍然应该检查 AWS lib 源以更新到 Swift 3 版本。因为它看起来像名称转换的坏情况。
  • @user28434 我正在使用(希望)该库的最新版本,正如这里所讨论的 github.com/aws/aws-sdk-ios/issues/413 我正在使用 2.4.9 版本,它已经转换为 swift 3(至少我希望,在 xcode 中打开我的整个项目期间,它要求我将所有内容转换为 swift 3,我点击了应用,结果出现了这个错误)
  • transferManager?.upload(uploadRequest).`continue` { ... } 也可能是一个解决方案。

标签: ios swift swift3 aws-sdk awss3transfermanager


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2017-02-05
    • 2017-01-25
    • 1970-01-01
    • 2016-07-09
    • 1970-01-01
    • 2016-07-11
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多