Search code examples
iosswiftsdkstoryboardbundle

How can I add a storyboard to an iOS SDK?


I'm developing an iOS SDK. I'm designing a screen that will appear in some actions. But I want to design these screens in .xib or storyboard. How can I do that?

This is how I did it:

let storyBoard: UIStoryboard = UIStoryboard(name: "Test", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "TestViewController") as! TestViewController

controller.present(newViewController, animated: true, completion: nil)

This throws the error:

Thread 1: "Could not find a storyboard named 'Test' in bundle


Solution

  • storyboardBundleOrNil: The bundle containing the storyboard file and its related resources. If you specify nil, this method looks in the main bundle of the current application.

    If you're building an SDK, then your storyboard is not on the main bundle, you have to specify the bundle:

    let storyBoard: UIStoryboard = UIStoryboard(name: "Test", bundle: Bundle(for: TestViewController.self)