1
votes

I am trying to add an init() ins swift so I can allocate PTKView at the top of the class so I can use it throughout my code.

I can create var PAymentVIew : PTKView in a function and it works fine but obviously not global.

So I created this at the top of the class :

class PaymentViewController: UIViewController , PTKViewDelegate {

    var PaymentView : PTKView
    var button   = UIButton.buttonWithType(UIButtonType.System) as UIButton

    init(PaymentView : PTKView , button : UIButton) {
        self.PaymentView = PaymentView
        self.button = button

    }

All I get at the moment is an horrible error saying :

required initialiser 'init(coder)' must be provided by subclass of UIViewController.

Any ideas at all would be brilliant.

1

1 Answers

1
votes

Add this to your vc:

required init(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

You're required to implement this initializer (thus the 'required' keyword). If you don't want to support it, just leave the fatalError so people know.

init(PaymentView : PTKView , button : UIButton) {
    self.PaymentView = PaymentView
    self.button = button
    super.init()
}