Axel
Axel

Reputation: 695

How to call loadView() from an xcode framework properly

override public func loadView() {
    NSBundle.mainBundle().loadNibNamed("DatePickerDialog", owner: self, options: nil)
}

This code is the usual way of linking a ViewController to its interface builder. However, once I moved these kinds of files to a framework, and make a call to it, it crashes. I know that I can override an init and specify the bundle ID but it won't pre-load the UI and will result from UI elements not initialized.

Upvotes: 1

Views: 93

Answers (1)

Abhinav
Abhinav

Reputation: 38162

Instead of calling NSBundle.mainBundle(), call either NSBundle(identifier: String) or NSBundle(forClass: AnyClass). The former takes an NSString argument of the framework's indentifier; the latter takes a Class argument of a class provided by the framework.

Upvotes: 1

Related Questions