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

查看:87
本文介绍了自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 属性添加到完成 param解决了这个问题。

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天全站免登陆