将我自己的Swift类导入Playground

时间:2023-01-23 18:16:08

I have seen several different posts on this subject, but none seem to solve what I think is a basic problem. In my project I have the following:

我已经看过几个关于这个主题的不同帖子,但似乎都没有解决我认为的基本问题。在我的项目中,我有以下内容:

Hi Class I have a Hi Class with a since method shown below

Hi Class我有一个Hi类,下面是如下所示的方法

func sayHi(){
    println("hi")

}

Playground I have a playground where I try to import my Hi Class.

游乐场我有一个操场,我尝试导入我的Hi Class。

The problem: My playground cannot see/import the Hi class. I know my Hi class is working as I can call it from a view controller without a problem.

问题:我的游乐场无法查看/导入Hi类。我知道我的Hi类正在工作,因为我可以从视图控制器调用它而没有问题。

Here the response from stack/apple forums that seem the most relevant

这里来自堆栈/苹果论坛的响应似乎最相关

It is now possible to import your own frameworks into a playground. This provides a way to share code between your applications and playgrounds, which can both import your frameworks. To do this, your playground must be in the same workspace as the project that produces your framework. You must have already built your framework. If it is an iOS framework, it must be built for a 64-bit run destination (e.g. iPhone 5s). You must have an active scheme which builds at least one target (that target's build location will be used in the framework search path for the playground). Your "Build Location" preference (in advanced "Locations" settings) should not be set to "Legacy". If your framework is not a Swift framework the "Defines Module" build setting must be set to "Yes". Once all these conditions are fulfilled, importing your framework will work in a playground

现在可以将自己的框架导入到游乐场中。这提供了一种在应用程序和游乐场之间共享代码的方法,这可以导入您的框架。为此,您的游乐场必须与生成框架的项目位于同一工作区中。您必须已经构建了框架。如果它是iOS框架,则必须为64位运行目标(例如iPhone 5s)构建。您必须拥有一个活动方案,该方案至少构建一个目标(该目标的构建位置将用于操场的框架搜索路径)。您的“构建位置”首选项(在高级“位置”设置中)不应设置为“旧版”。如果您的框架不是Swift框架,则“定义模块”构建设置必须设置为“是”。一旦满足所有这些条件,导入框架将在游乐场中运行

Source: How to I import 3rd party frameworks into Xcode Playground?

来源:如何将第三方框架导入Xcode Playground?

Can anyone point me to a step by step on how to do this ?

任何人都可以指点我一步一步如何做到这一点?

1 个解决方案

#1


15  

In Xcode 7 there is a Sources folder in the Navigator Cmd1 that will import any swift code locally in your playground.

在Xcode 7中,导航器Cmd1中有一个Sources文件夹,它将在您的操场上本地导入任何快速代码。

将我自己的Swift类导入Playground

Beware that you need to mark the classes and functions in the Sources as public.

请注意,您需要将Sources中的类和函数标记为公共。

#1


15  

In Xcode 7 there is a Sources folder in the Navigator Cmd1 that will import any swift code locally in your playground.

在Xcode 7中,导航器Cmd1中有一个Sources文件夹,它将在您的操场上本地导入任何快速代码。

将我自己的Swift类导入Playground

Beware that you need to mark the classes and functions in the Sources as public.

请注意,您需要将Sources中的类和函数标记为公共。