I am creating an app on playground, I added a Main.storyboard file in this project. but when its compile, it gives me the following error.
NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main' in bundle NSBundle
so i start thinking that it maybe some typo, so that's why this error generates. but this was not the problem, so i start searching on google, and stackoverflow, but did not find the solution about my problem. There are many questions on stackoverflow with the following content however, each has a very specific scenario.
then i find a playground project from github, in which the developer added a main storyboard and its compiling perfectly, but its extension is Main.storyboardc. then i search about storyboardc extension. so i understand its a compile storyboard. then for just checking i double tap the the Main.storyboard and change its name to Main.storyboadc. then the following error generates
'NSInvalidArgumentException', reason: 'There doesn't seem to be a valid compiled storyboard
Now at this point I am sure that i have to compile my storyboard first then it will add in my playground, because with out .storyboardc extension, it did not even find the Main storyboard. as i stated above. so again i already check all the material on stackoverflow, each has a very specific scenario. so guide me how to compile main.storyboard.
Add new storyboard to the project by File->New->File... ->Userinterface->storyboard. Go to project summary and select MainStoryboard and select the storyboard name you just created.
The compiler for storyboards (and all the other interface builder files) is called ibtool . The resulting files from the process have the extension . storyboardc .
Basic Swift Code for iOS Apps Storyboards help us create all the screens of an application and interconnect the screens under one interface MainStoryboard. storyboard. It also helps in reducing the coding of pushing/presenting view controllers.
The command ibtool
will do exactly this for you.
So for example, you can run
ibtool --compile Main.storyboardc Main.storyboard
inside the terminal.
After that, all relevant files (Info.plist and .nib files) will be created inside the Main.storyboardc.
Now you can take that .storyboardc
file and place it inside a project and reference the files inside the storyboard as you normally would.
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let viewController = storyboard.instantiateViewController(withIdentifier: "MyViewController")
A .storyboardc
file is nothing more than a group of nib files.
For more information have a look at the manual page man ibtool
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With