Swift游乐场可以查看同一项目中的其他源文件吗? [英] Can Swift playgrounds see other source files in the same project?

查看:87
本文介绍了Swift游乐场可以查看同一项目中的其他源文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中的另一个Swift文件中创建了最简单的自定义类:

I created the most simple custom class in a separate Swift file in my project:

class Foo
{
    init()
    {
        println("I made a foo.")
    }
}

然后,在同一项目的操场上,我尝试了

Then, in a playground within the same project, I tried

var x = Foo()

Xcode似乎不喜欢这样,并告诉我, Foo'是一个未解决的标识符。我对操场如何适应项目其余部分感到困惑,因为我项目中的其他任何Swift文件都可以毫无问题地解决 Foo问题。

Xcode didn't seem to like this, and told me that 'Foo' is an unresolved identifier. I'm somewhat confused about how playgrounds fit into the rest of the project structure, since any other Swift file in my project can resolve 'Foo' without issue.

我可以使我的游乐场能够使用在项目中其他Swift文件中定义的自定义类吗?我尝试为构建目标命名产品模块,然后将其导入到Playground中,但没有成功:Playground无法识别产品模块的名称。

How can I make my playground able to use custom classes I define in other Swift files in my project? I have tried naming the product module for the build target and importing that into the playground, with no success: the playground doesn't recognize the name of the product module.

在此先感谢您的协助。我知道这很简单。

Thanks in advance for the assistance. I know it is something simple.

推荐答案

他们不能。操场是独立的。希望将来会有所改变。

They cannot. Playgrounds are self-contained. This will hopefully change in the future.

编辑:从Xcode 6.3开始,Playgrounds现在可以包含支持代码。他们仍然看不到同一项目中的其他代码,但是可以将代码添加到Playground的支持文件夹中,以便在操场上使用。有关更多信息,请参见 Swift博客

As of Xcode 6.3, Playgrounds can now contain supporting code. They still cannot see other code in the same project, but code can be added to the support folder of a Playground that can be used from within the playground. See the Swift blog for more info.

这篇关于Swift游乐场可以查看同一项目中的其他源文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆