【问题标题】:iOS AWS protocol methods with Error type as parameter causes protocol to not conform错误类型作为参数的 iOS AWS 协议方法导致协议不符合
【发布时间】:2017-11-04 23:50:18
【问题描述】:

我正在使用 AWS Mobile Hub 为我用 Swift 编写的 iOS 应用程序实现登录。直到本周,它运行良好,但更新到 Xcode 9.1 导致发生了几个构建错误。我还有 2 个错误。两者都涉及专门对协议的调用; 'AWSSignInDelegate' 和 'AWSCognitoIdentityPasswordAuthentication'。

extension SignInVC: AWSSignInDelegate
{
   func onLogin(signInProvider: AWSSignInProvider, result: Any?, error: Error?)
   {
      //Code
   }
}

extension SignInVC: AWSCognitoIdentityPasswordAuthentication
{
   func getDetails(_ authenticationInput: AWSCognitoIdentityPasswordAuthenticationInput, passwordAuthenticationCompletionSource: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>)
   {
      //Code
   }

   func didCompleteStepWithError(_ error: Error?)
   {
      //Code
   }
}

错误:

类型“SignInVC”不符合协议“AWSSignInDelegate”

候选人的类型不匹配'(AWSSignInProvider, Any?, Error?) -> ()'

类型“SignInVC”不符合协议“AWSCognitoIdentityPasswordAuthentication”

候选人的类型不匹配'(Error?) -> ()'

我目前所拥有的: 错误仅发生在包含快速类型“错误”作为参数的方法中。上面的“getDetails”调用似乎不会像其他 2 种方法那样引发错误。

这里有一个类似的问题: Cannot conform to STPAddCardViewControllerDelegate since Xcode 8 GM on Swift 3

建议将@escaping 添加到完成块以修复类似的错误。我的问题不涉及完成块。所以我假设我错误地将 swift Error 类型作为参数处理,因为这两种方法在 objc 中的实现使用 NSError。

关于如何解决此问题的任何建议? 非常感谢!

【问题讨论】:

    标签: ios swift xcode amazon-web-services


    【解决方案1】:

    我发现标准的 Swift Error 类型正在被我项目中其他地方的一个名称不佳的 Error 类所覆盖。

    【讨论】:

      【解决方案2】:

      我对 AWS 不是很熟悉,但我浏览了有关您正在使用的协议的文档,并且函数名称不太匹配,请在此处查找我认为是最新的名称。

      http://docs.aws.amazon.com/AWSiOSSDK/latest/Protocols/AWSCognitoIdentityPasswordAuthentication.html

      http://docs.aws.amazon.com/AWSiOSSDK/latest/Protocols/AWSSignInDelegate.html

      【讨论】:

      • 感谢您的尝试...可以肯定这不是问题: 1. 我认为自从我一个月前首次实施这些方法以来,这些都没有改变。 2. 我进行的调用仍然是为协议创建的自动生成的存根。 3. 如果我跳转到 AWSSignInDelegate 的定义,onLogin 被列为:NS_SWIFT_NAME(onLogin(signInProvider:result:error:)) 用于实现“onLoginWithSignInProvider”方法。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多