0

I'm trying to implement the Objective-C equiv. below when calling a view controller with a nib.

Objective C:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.modalPresentationStyle = UIModalPresentationCustom;
        self.transitioningDelegate = self;
    }
    return self;
}

Here is where i am in swift so far:

override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)

    self.modalPresentationStyle = UIModalPresentationStyle.Custom
    self.transitioningDelegate = self
}

However i keep getting this error:

Class "ViewController" does not implement its superclass's required members

I thought the init method above was it required members?

Edit - Goes into more detail below: Class does not implement its superclass's required members

Community
  • 1
  • 1
Fudgey
  • 3,793
  • 7
  • 32
  • 53

1 Answers1

5

You must implement base class required initializers. In your case you should add code bellow to your VC class:

required init(coder aDecoder: NSCoder!) {
    super.init(coder: aDecoder)
}

Since Beta 5:

The required modifier is written before every subclass implementation of a required initializer. Required initializers can be satisfied by automatically inherited initializers.

Remarks:

required init(coder aDecoder: NSCoder!) { ... } should be added only if you override at least one init method in your class.

Keenle
  • 12,010
  • 3
  • 37
  • 46
  • If you find that this solution doesn't work for you in Swift2, you have to make it optional. required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } CREDIT: http://stackoverflow.com/questions/33087478/ios-9-errors-and-correct-conversion-to-swift-2 – eimmer Jun 13 '16 at 16:57