Rewriting an Objective-C parameterless init to Swift convenience init

I have an Objective-C initializer (from another project) which I've found useful. Now I want to port it to Swift and there's a problem with Swift's naming convention.

.h

@interface UIViewController (FromNib)
-(nullable instancetype)initFromNib;
@end

.m

#import "FromNib.h"

@implementation UIViewController (FromNib)

-(nullable instancetype)initFromNib {

    self = [self initWithNibName: NSStringFromClass([self class])
                          bundle: [NSBundle mainBundle]];

    if (self == nil) {

        NSLog(@"\nNib with name %@ not found in the main bundle.\n", NSStringFromClass([self class]));
    }

    return self;
}

@end

Since Objective-C recognizes methods which names begin with init it treats init as distinct from initWith... or initFrom. Swift makes the distinction based on passed arguments. The only way (I have thought of) to make init() different from my initializer is to pass a dummy argument:

extension UIViewController {

    convenience init(FromNib:Int) {
        self.init()
        // the rest of the code
    }
}

Is there a different way to write a parameterless init in Swift, and to avoid it being confused with the designated init()?

Answers


@Sulthan and @Martin R

Good point. The default init() does exactly that. Thank you. Problem solved.


Need Your Help

Bootstrap Modal + PHP + AJAX

php ajax twitter-bootstrap modal-dialog

So I can attest that I am an idiot/newb/.