由于 Swift 3 上的 Xcode 8 GM 无法符合 STPAddCardViewControllerDelegate [英] Cannot conform to STPAddCardViewControllerDelegate since Xcode 8 GM on Swift 3

查看:14
本文介绍了由于 Swift 3 上的 Xcode 8 GM 无法符合 STPAddCardViewControllerDelegate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从使用 Xcode 8 GM 将我的代码库转换为 swift 3 后,我在尝试符合 STPAddCardViewControllerDelegate (Stripe SDK) 时遇到此错误.我对这个错误感到非常惊讶,因为即使在使用 Xcode 自动存根这些方法时,我也会遇到同样的错误.类型似乎匹配,不知道发生了什么.

Since converting my codebase to swift 3 with Xcode 8 GM, I get this error when trying to conform to the STPAddCardViewControllerDelegate (Stripe SDK). I'm very surprised by this error because even when stubbing those methods automatically with Xcode I encounter the same error. Types seem to match, no idea what's going on.

extension ViewController: STPAddCardViewControllerDelegate {

    func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController) {
    }

    func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreateToken token: STPToken, completion: STPErrorBlock) {
    }
}

产生这个错误

Type 'ViewController' does not conform to protocol 'STPAddCardViewControllerDelegate'

Protocol requires function 'addCardViewController(_:didCreateToken:completion:)' with type '(STPAddCardViewController, STPToken, STPErrorBlock) -> Void'; do you want to add a stub?

Candidate has non-matching type '(STPAddCardViewController, STPToken, (Error?) -> Void) -> ()'

这是协议的定义

public protocol STPAddCardViewControllerDelegate : NSObjectProtocol {
    public func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController)
    public func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreateToken token: STPToken, completion: Stripe.STPErrorBlock)
}

我在这里遗漏了什么?

推荐答案

经过@AliSoftware 和@bdorfman 在相关Stripe SDK 问题,发现将 @escaping 属性添加到 completion 参数可以解决此问题.

After a bit of investigation from @AliSoftware and @bdorfman in the related Stripe SDK issue, it's been found that adding the @escaping attribute to the completion param fixes the issue.

好像是编译器&swift 端的存根问题,目前在此处跟踪:https://bugs.swift.org/browse/SR-2596.

It seems to be a compiler & stubbing issue on swift's end, that is currently tracked here: https://bugs.swift.org/browse/SR-2596.

这篇关于由于 Swift 3 上的 Xcode 8 GM 无法符合 STPAddCardViewControllerDelegate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆