gpt4 book ai didi

xcode - XCode Playgrounds 中相互引用的来源

转载 作者:搜寻专家 更新时间:2023-11-01 07:29:01 25 4
gpt4 key购买 nike

我的 Xcode Playground 的 Sources/ 目录中有代码。我可以在我的 Playground 上很好地引用它们,但我如何让它们相互引用?例如,假设我在 Sources/ 目录中有 A.swiftB.swift 文件。我想让 A.swiftB.swift 访问一些东西,但是我得到一个错误,说 B.swift 的东西是在 A.swift 中未定义。

我怎样才能做到这一点?

最佳答案

public 属性添加到您想要在其他playground 中访问的类、方法和属性。这应该可以解决您的问题:

You have to add public access attribute to your classes, methods and properties in source folder to make them accessible from main playground file as they treated as separate module by compiler

更新:

我找到了 this thread ,虽然我认为这不是专门针对这个主题回答了这个问题,但以下是公认的答案:

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

Edit: 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.

所以,正如我之前所说,可以访问 sources 文件夹,但不能访问其他 playground。

关于xcode - XCode Playgrounds 中相互引用的来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33880727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com