4

I am trying to initialize a subclass of UIViewController that has a corresponding .xib file.

I do it via:

LandingVC()

However, this doesn't initliaze it with the xib file. I have to do it manually via:

LandingVC(nibName: "LandingVC", bundle: nil)

What I am confused about is that in Objective-C, I could do this:

[[LandingVC alloc] init]

and it would automaitcally infer the xib name (if it exists). Why doesn't this work in Swift?

Thanks

5
  • In Objective-C, there is a method - [[LandingVC alloc] initWithNibName:@"LandingVC " bundle:nil]; is serving the same purpose. Commented Sep 1, 2015 at 11:49
  • Do you have xib named as Modulename.class name.xib ? Commented Sep 1, 2015 at 11:50
  • @Mrunal you don't understand my question.. In Objective-C I don't have to do initWithNibName, just init, and it would atomically infer the nib name. In Swift it doesn't do that. Commented Sep 1, 2015 at 11:51
  • @rshev I just have a xib named class_name.xib (LandingVC.nib) added to my bundle. Commented Sep 1, 2015 at 11:53
  • @0xSina : Okay got your question now. Commented Sep 1, 2015 at 15:17

1 Answer 1

3

To instantiate a View Controller with automatically loading .xib in swift name your xib file as Module name.Class name.xib

It was mentioned in Apple documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.