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

时间:2023-01-23 19:07:45

Is it possible to load a storyboard in an iOS Playground? Follow the steps in this questions:

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

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

如何从iOS操场中的文件实例化故事板?

Compiled Main.storyboard using

编译Main.storyboard使用

ibtool --compile MainMenu.nib MainMenu.storyboard

Added it to the Resources folder of the playground. Then tried loading it:

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

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

This resulting in an error:

这导致错误:

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

Is this supported in XCode 7.3.1 or even XCode 8?

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

2 个解决方案

#1


4  

Your storyboard init code works for me if I set up the resource section of the playground with the same structure as an app.

如果我设置操场的资源部分与应用程序具有相同的结构,那么您的storyboard初始化代码适用于我。

Resources->Base.lproj->Main.storyboardc

#2


1  

After many attempts, I finally got this working. A few caveats:

经过多次尝试,我终于完成了这项工作。一些警告:

1.. Compile the storyboard using

1 ..使用编译故事板

ibtool --compile MainMenu.storyboardc MainMenu.storyboard

Not using

ibtool --compile MainMenu.nib MainMenu.storyboard

2.. Place the compiled storyboardc file in the Resources folder of the playground, not the Sources folder

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

3.. Specify module name using --module flag when compiling. Otherwise, your outlets may cause a runtime error. For the playground book, the module name is Book_Sources. For your own playground, the module name is [Playground name]_Sources. Note I didn't find any of this in Apple's documentation, so it is subject to change. The final command looks like this:

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

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

#1


4  

Your storyboard init code works for me if I set up the resource section of the playground with the same structure as an app.

如果我设置操场的资源部分与应用程序具有相同的结构,那么您的storyboard初始化代码适用于我。

Resources->Base.lproj->Main.storyboardc

#2


1  

After many attempts, I finally got this working. A few caveats:

经过多次尝试,我终于完成了这项工作。一些警告:

1.. Compile the storyboard using

1 ..使用编译故事板

ibtool --compile MainMenu.storyboardc MainMenu.storyboard

Not using

ibtool --compile MainMenu.nib MainMenu.storyboard

2.. Place the compiled storyboardc file in the Resources folder of the playground, not the Sources folder

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

3.. Specify module name using --module flag when compiling. Otherwise, your outlets may cause a runtime error. For the playground book, the module name is Book_Sources. For your own playground, the module name is [Playground name]_Sources. Note I didn't find any of this in Apple's documentation, so it is subject to change. The final command looks like this:

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

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