无法符合 STPAddCardViewControllerDelegate,因为 Xcode 8 GM on Swift 3
Cannot conform to STPAddCardViewControllerDelegate since Xcode 8 GM on Swift 3
自从使用 Xcode 8 GM 将我的代码库转换为 swift 3 后,我在尝试符合 STPAddCardViewControllerDelegate
(Stripe SDK) 时遇到此错误。我对这个错误感到非常惊讶,因为即使在使用 Xcode 自动存根这些方法时,我也会遇到同样的错误。类型似乎匹配,不知道发生了什么。
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 issue 中的一些调查后,发现将 @escaping
属性添加到 completion
参数可以解决问题。
这似乎是 swift 端的编译器和存根问题,目前已在此处跟踪:https://bugs.swift.org/browse/SR-2596。
自从使用 Xcode 8 GM 将我的代码库转换为 swift 3 后,我在尝试符合 STPAddCardViewControllerDelegate
(Stripe SDK) 时遇到此错误。我对这个错误感到非常惊讶,因为即使在使用 Xcode 自动存根这些方法时,我也会遇到同样的错误。类型似乎匹配,不知道发生了什么。
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 issue 中的一些调查后,发现将 @escaping
属性添加到 completion
参数可以解决问题。
这似乎是 swift 端的编译器和存根问题,目前已在此处跟踪:https://bugs.swift.org/browse/SR-2596。