initialization error when trying to segue or instantiate to vc

I am trying to do a data transfer to CheckoutViewController that was coded programmatically. Before I connected the CheckoutViewController to storyboards, the view was loading perfectly fine and my initializers weren't causing any issues. This is the block of code I had in the CheckoutVC.

Code Block  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: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
   

Now when I try to load the vc after setting it up in storyboard, it crashes with a fatal error, how can I fix this?

Replies

Before I connected the CheckoutViewController to storyboards

What do you mean ?
That app did "work" before you did any connection ?
What did you connect ? The IBOutlets ? The IBActions ?

What crash message do you get ?
Please show the complete code for the ViewController, with its IBOutlet declarations and all the code.

It's not very good to have super.init on line 13, in the middle.
Move it at the beginnng of init()

Now when I try to load the vc after setting it up in storyboard, it crashes with a fatal error, how can I fix this?

When you instantiate a view controller through storyboard, iOS calls init?(coder:) internally. You need to implement it.
Code Block
required init?(coder: NSCoder) {
let config = STPPaymentConfiguration()
let paymentContext = STPPaymentContext(customerContext: customerContext, configuration: config, theme: .defaultTheme)
config.requiredBillingAddressFields = .name
self.paymentContext = paymentContext
self.config = config
super.init(coder: coder)
self.paymentContext.delegate = self
self.paymentContext.hostViewController = self
}

(If this does not solve your issue, you may need to show more info about the class and the storyboard settings.)