【发布时间】:2021-06-17 00:19:37
【问题描述】:
所以我的目标是将数据传输到 Stripe 为其 API 提供的CheckoutViewController()。所以像往常一样,我去了故事板并将一个新的 vc 与 CheckoutViewController() 类连接起来,这样我就可以从我的另一个 vc 中转到它并进行数据传输。
在此之前,我只是在推送 vc,它工作正常,并且知道我可以实例化它并进行数据传输,但即使我尝试这样做,我也会收到一个致命错误:
Fatal error: init(coder:) has not been implemented
这是我在CheckoutVC 中的代码:
let paymentContext: STPPaymentContext?
let config: STPPaymentConfiguration
let customerContext = STPCustomerContext(keyProvider: MyAPIClient())
init() {
let config = STPPaymentConfiguration()
let paymentContext = STPPaymentContext(customerContext: customerContext, configuration: config, theme: .defaultTheme)
config.requiredBillingAddressFields = .name
self.paymentContext = paymentContext
self.config = config
super.init(nibName: nil, bundle: nil)
self.paymentContext?.delegate = self
self.paymentContext?.hostViewController = self
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
我更改了required init,因为我阅读了this post on init errors,但现在它甚至在运行之前就给出了错误:
Property 'self.paymentContext' not initialized at super.init call
在我将课程连接到情节提要中的 vc 之前,这一切都有效,但我确实别无选择,我需要为用户进行数据传输以支付适当的金额。我不明白self.paymentContext 是如何没有初始化的,我以前用过这个就好了。有人知道我该如何解决或解决它吗?
init() {
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
let config = STPPaymentConfiguration()
let paymentContext = STPPaymentContext(customerContext: customerContext, configuration: config, theme: .defaultTheme)
config.requiredBillingAddressFields = .name
self.paymentContext = paymentContext
self.config = config
self.paymentContext?.delegate = self
self.paymentContext?.hostViewController = self
super.init(coder: aDecoder)
}
像这样?
【问题讨论】:
标签: ios swift initialization stripe-payments nscoder