是否可以在 iOS Playground 中加载故事板?

Is it possible to load a storyboard in an iOS Playground?

是否可以在 iOS Playground 中加载故事板? 请按照以下问题中的步骤操作:

使用

编译Main.storyboard
ibtool --compile MainMenu.nib MainMenu.storyboard

已将其添加到 playground 的 Resources 文件夹中。然后尝试加载它:

let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())

这导致错误:

Playground execution aborted: Execution was interrupted, reason: signal SIGABRT.

XCode 7.3.1 甚至 XCode 8 是否支持此功能?

如果我使用与应用程序相同的结构设置 playground 的资源部分,你的故事板初始化代码对我有用。

资源->Base.lproj->Main.storyboardc

经过多次尝试,我终于搞定了。一些注意事项:

1.. 使用

编译故事板
ibtool --compile MainMenu.storyboardc MainMenu.storyboard

没有使用

ibtool --compile MainMenu.nib MainMenu.storyboard

2..将编译好的storyboardc文件放在playground的Resources文件夹下,而不是Sources文件夹下

3.. 编译时使用 --module 标志指定模块名称。否则,您的网点可能会导致运行时错误。对于 playground book,模块名称是 Book_Sources。对于您自己的游乐场,模块名称是 [Playground name]_Sources。请注意,我没有在 Apple 的文档中找到任何此类内容,因此它可能会有所更改。 最终命令如下所示:

ibtool --compile MainMenu.storyboardc MainMenu.storyboard --module Book_Sources