Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading a storyboard from a framework

I'm creating a library with Cocoapods and Swift 1.2. I have a storyboard that I have to load in my library. Although, I am always getting this same error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main' in bundle`.

What I have tried:

  • put my storyboard inside the Classes folder
  • put my storyboard inside the Assets folder
  • Delete my application from the device, clean the project and re-build.
  • Use UIStoryboard(name:"Main", bundle:nil)
  • Use UIStoryboard(name:"Main", bundle:NSBundle(forClass:self))
  • Use UIStoryboard(name:"Main", identifier:myIdentifier)

I was although able to load the storyboard from my example project, put then I was only able to instantiate the initial view controller.

Trying to invoke storyboard!.instantiateViewControllerWithIdentifier(someIdentifier) from the initial view controller always resulted in the view controller not being found, although I can clearly see that there is a view controller with that identifier. How can I fix this issue?

like image 971
user26830 Avatar asked Jul 28 '15 12:07

user26830


People also ask

How do I copy a storyboard in Xcode?

Select the View Controller in the storyboard and press Command + C to copy. Then press Command + V to paste in the second storyboard.

How do I add a framework in Swiftui?

There are two ways to add the project to your app: Drag the framework into the project navigator, and then add the framework to the target. Add the framework to the project, and then add the framework to the target.


1 Answers

Found the problem. Just silly but after deleting the Main.storyboard from the project, I didn't remove it from the project's settings. Trying to load it as the initial view controller. After changing the settings, UIStoryboard(name:"Main", bundle:NSBundle(forClass:self) just works properly.

like image 111
user26830 Avatar answered Oct 14 '22 06:10

user26830