I have seen both of these being used a lot but I can't find what the difference is:
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
So what's the difference between setting bundle to nil
or to NSBundle.mainBundle()
?
Actually there is no difference between those two. Whether you specify nil
or NSBundle.mainBundle()
both will refer to main bundle.
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.
Reference: UIStoryboard Class Reference
The bundle:
parameter will become useful when you need to access the info from another bundle, apart from mainBundle()
. For example, many third-party libraries ship with their own bundle for wrapping up the resources used by that particular library. So if you want to access those resources you need to refer that bundle.