Could not find a storyboard named 'MainStoryBoard' in bundle NSBundle
I have started a new app a few days ago and began working with the simulator to test it. I started as an empty project and manually added the storyboard. The simulator builds and runs my app just fine but when I try to build to my iPhone I get the messsage 'Could not find a storyboard named 'MainStoryBoard' in bundle NSBundle'.
Google turned up nothing and this question suggested I checked my target for the storyboard, but everything is in place. Even so, if something wouldn't be in place, the simulator wouldn't run either.
Can anyone point me in the right direction?
The simulator is not case sensitive, but the device is. If your storyboard is called MainStoryboard, not MainStoryBoard, this will cause your problem.
I had my app working normally on the iPhone Simulator but strangely Xcode stopped responding and i had to Force Quit Xcode. When I restarted Xcode i encountered "Could not find a storyboard named MainStoryboard....",
I have fixed this issue by following below steps:
- Renaming "MainStoryboard.storyboard" to "MainStoryboard_1.storyboard"
- Open file "$your_app$-Info.plist" located in "Supporting Files" folder. Edit "Main storyboard file base name" to "MainStoryboard_1.storyboard".
- Rerun the app, and it worked for me.
- I renamed my storyboard file back to its original "MainStoryboard.storyboard".
- Edited the .plist file back to its original.
- Rerun the app, and it worked for me.
For some reason the file "MainStoryboard.storyboard" was not recognised after force quitting Xcode and following above steps made the app recognise the file back again.
Hope this solution helps..
Just want to mention scenario I encountered. I don't know how, but storyboard disconnected from the target although it still was part of the project. To fix this I opened storyboard, selected "File Inspector"(leftmost icon on the right panel) and check the project under "Target membership". Hope it helps someone.
The problem occurs when you deselect "Use Base Internationalization" and run simulator in different locale rather than your specific localization.
For example, you specify a zh-CN localization in project setting but run simulator under en-US.
Tried all solutions mentioned above but didn’t worked.
After thorough research found the culprit:
Copy Bundle Resource was missing from TARGETS -> Build Phases
This got accidentally removed while removing Cocoapods.
Below are steps to fix this :
- Go to TARGETS of your project
- Click on plus (+) button present on top left corner
- Select New Copy Bundle Resources from drop down
- Now, add you Storyboard files (Main, Launchscreen etc). Also add Assets folder. You can add these files by clicking on plus (+) button present in bottom
- Delete the derived data content
- Delete the app from Simulator/Device and run again
I thought you may have deleted the storyboard and decided to use a .xib file on initial app launch. In this scenario, Xcode would try to find a nonexistent storyboard.
For this case, click on the Project > Info > Custom iOS Target Properties and delete this key value pair: Main storyboard file base name
This helped me (Swift 2.1, Xcode 7.2) for an app with a tab bar
let storyboard: UIStoryboard = UIStoryboard(name:"Main",bundle: NSBundle(forClass: self.dynamicType)) let tabController = storyboard.instantiateViewControllerWithIdentifier("MyTabBarIdentifier") as! UITabBarController
I had the Main.storyboard with the correct target membership, copy bundle resources, cleaned build folder, etc (most of the answers were pointing to this).
A simple Clean corrected the error for me.
Nitin Alabur's answer helped me, but indirectly. Posting another answer to clarify:
I am building a dynamic framework with a storyboard inside it, and in the test app I am building to test the framework, I was getting this error.
My code looked like this:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:nil];
I was ignoring the NSBundle stuff because, hey, I don't know what the heck a bundle is. Turns out it's important for this use case, where the storyboard will exist outside of the application's "bundle" (it's in my framework's bundle instead). This code will tell iOS to find the storyboard within the bundle that the current class exists in (which for me, is the bundle that contains my framework):
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:[NSBundle bundleForClass:[self class]]];
If you are using for navigation on source code, try to use below code
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
Often people will enter "Main.storyboard" for the name, since that is literally the name of the file, but for the purposes of Obj-C coding, "X.storyboard" has the name "X", so in this case, @"Main".
Go to your project, select your target and pull down from the menus to re-select your storyboards.
Also, you can update your plist, I found that changing one did not change the other.
You just need to check your configuration file (.plist) under Supporting files folder
Check the name of your default storyboard.
I also had same issue, what caused this type of exception is I had written "Main.storyboard" instead of "Main". We don't have to specify .storyboard extension.
To prevent this from happening I have had to change the way I work with storyboard files. After editing the storyboard save the file then exit XCode. This seems to prevent the problem from occurring.
I had this problem when I accidentally opened a project with a second install of Xcode. It broke my project files permanently (which is understandable).
This problem happened for me when i was calling storyboard in code.The reason was i used different 'word' for storyboard.I solved it like this
Go to Targets ->info , select info,copy name of storyboard and paste it to where you are calling storyboard.
At least give a try….
This happened to me when I had a previous app with the same name installed on the simulator.
I have removed the previous app, re-selected the Storyboard on the "Deployment Info", re-run the app, and everything worked fine.
I had similar problem and I was getting the following error.
exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'MainStoryboard_iPhone' in bundle NSBundle
I fixed it by updating the plist file. Simply goto Edit->Find->Find in Workspace and search for "story". Now update the appropriate name for the story board.
If you recently reset your iOS sim to default settings, it's also useful to check locale settings in its Preferences. I'm working on the app with Russian as the only locale and after sim reset the xCode stopped to start the app because the sim locale was set to English.
I had this error on the device when I added about 150 fonts to UIAppFonts. After I reduced their count to about 100, it went away.
I had this problem in a project that had storyboards with and without ~iPad or ~iPhone suffixes, like MainStoryboard.storyboard and MainStoryboard~iPad.storyboard.
The problem was that MainStoryboard.storyboard was overwriting MainStoryboard~iPad.storyboard when it got compiled into the build directory. If the files were compiled in the opposite order, both would be preserved without issue. I have no idea why this happens.
To get around this, you can stop using ~iPad/iPhone suffixes or make sure the files are in the right order in the Copy Bundle Resources phase.
A very silly one but I had "MainStoryboard.storyboard" in the "Main storyboard file base name (iPad)" entry of my my .plist instead of just "MainStoryboard".
The solution for me was, that I just needed to add the MainStoryboard to the Bundle Resources. After that, it works fine.
Project -> Build Phases -> Copy Bundle Resources -> click on the + button and add your file.
Go to your info.plist on Build Phases > Copy Bundle Resources and add your storyboard using the icon "+"
In my case, it was a storyboard inside a framework for a Mac application. I was using:
let storyboard = NSStoryboard(name: "StoryboardName", bundle: nil)
and needed to use the framework's bundle identifier to get the correct bundle:
let storyboard = NSStoryboard(name: "StoryboardName", bundle: Bundle(identifier: "com.company.FrameworkName"))
There are 2 possibilities,
- Make sure your Storyboard is added to your target.
Select Storyboard > Go to file inspector (first right tab) > Check Target Membership
Initialize storyboard with proper bundle.
- If storyboard is in same target you are working on then use bundle = nil
If storyboard is in different target than you are working on, then try following code to initialize bundle and storyboard.
let bundle = Bundle(for: MyClass.self) let storyboard = UIStoryboard(name: "Main", bundle: bundle)