How do you instantiate a Storyboard from a file within an iOS playground?

我只是一个虾纸丫 提交于 2019-11-30 07:03:00
Martin Lockett

I found this:

"You can throw a xib file into your Resources, but the playground cannot read it or run it because it’s not in compiled form. Today, I (finallly!) thought of using ibtool to pre-compile my MainMenu.xib file into nib and then load that. When you install Xcode’s command line tools, ibtool gets added to /usr/bin. So all you need to do to compile your nib is issue the following command:

ibtool --compile MainMenu.nib MainMenu.xib`

Throw that resulting nib into your playground’s resources folder and you’re ready to load it up."

at http://ericasadun.com/2015/03/25/swift-todays-wow-moment-adding-menus-to-playgrounds/

Your storyboard will be compiled into multiple nibs (one per scene)

Hope it helps

Similar to @ybakos answer, but for accessing a framework with a storyboard you want to load (then both the Playground and your app can use the same storyboard directly):

If you have a Storyboard in a framework that has been compiled for the simulator and is also embedded in a working project that furthermore lives in a workspace, you will be able to load the framework in a playground in that same workspace via the framework bundle, like so:

let frameworkBundle = Bundle(identifier: "com.kigisoft.KGWeatherMap")
let storyboard = UIStoryboard(name: "WeatherMap", bundle: frameworkBundle)

You can download a sample project "StoryboardPlay" from this Dropbox link:

Playground Example Projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!