xcode Objective-C 的游乐场
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26108038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Playgrounds for Objective-C
提问by Tarek
Is it at all possible to have Xcode create a .playground file for Objective-C instead of Swift? Are there any available Xcode plugins that allow that?
是否有可能让 Xcode 为 Objective-C 而不是 Swift 创建一个 .playground 文件?是否有任何可用的 Xcode 插件允许这样做?
采纳答案by Victor Sigler
There is a very good library developed by Krzysztof Zab?ockiin Github entitled KZPlaygroundthat support both code in Playgrounds for Objective-C and Swift and a lot of cool features.
有一个由Krzysztof Zab? ocki在 Github 上开发的非常好的库,名为KZPlayground,它同时支持 Objective-C 和 Swift 的 Playgrounds 代码以及许多很酷的功能。
I hope this can help you.
我希望这可以帮助你。
回答by slcott
You can quickly test code snippets using a test case in a new project. Just create a new project and go to the Navigatorin the left pane and hit the Test Navigatorbutton. Then follow this guide
您可以在新项目中使用测试用例快速测试代码片段。只需创建一个新项目并转到左侧窗格中的Navigator并点击Test Navigator按钮。然后按照本指南
The setup code will look a little different than a swift playground, but it still allows you to prototype and play around.
设置代码看起来与 swift playground 略有不同,但它仍然允许您进行原型设计和尝试。
回答by TheFuquan
回答by Enrico Granata
There are enough moving parts in a playground, and all of those would have to be reimplemented for Objective-C. Reliable playgrounds also depend on definite initialization which Objective-C does not have.
在操场上有足够多的活动部件,所有这些都必须为 Objective-C 重新实现。可靠的 Playground 还依赖于 Objective-C 没有的明确的初始化。
For instance consider:
例如考虑:
var d: NSData // this is not initialized, so I can't use it
vs.
对比
NSData *d; // this is also not initialized, but now I can use it
If I am the person storing the description of your NSData for the sidebar, now I know that I am not supposed to do
如果我是为侧边栏存储 NSData 描述的人,现在我知道我不应该这样做
describe(d)
in the Swift case, but for the Objective-C case, I don't have equal knowledge and I run the risk of saying
在 Swift 的情况下,但对于 Objective-C 的情况,我没有同等的知识,我冒着说的风险
[d description]; // even though d is a random pointer now.. oops, I just crashed!
In short, I don't think any such thing exists, and making one work would also involve some trickery
总之,我觉得不存在这样的东西,做一个作品也会涉及到一些诡计