如何将自己的类从您自己的项目导入Playground [英] How to import own classes from your own project into a Playground

查看:207
本文介绍了如何将自己的类从您自己的项目导入Playground的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设这样的设置:


  • 你有一个Xcode 6项目,你已经实现了自己的类(比如MyView和使用Objective-C和Swift的MyViewController

  • 您已将Playground添加到项目中

在Playground中,可以使用 import 关键字导入模块(框架),如 UIKit 。如何从Playground启用对项目其他类的访问?

In the Playground, it's possible to import modules (frameworks) like UIKit with the import keyword. How do you enable access to the project's other classes from the Playground?

只是尝试直接访问项目类会产生错误消息:
使用未解析的标识符'MyView'

Just trying to access project classes directly results with an error message: Use of unresolved identifier 'MyView'

推荐答案

从Xcode 6.0 Beta 5开始,现在可以导入自己的框架进入游乐场。这提供了一种在应用程序和游乐场之间共享代码的方法,这可以导入您的框架。为此:

As of Xcode 6.0 Beta 5, 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:


  1. 您的游乐场必须与生成框架的项目位于同一工作区中。您的工作区必须包含生成框架的目标,而不是使用预先构建的框架。

  1. Your playground must be in the same workspace as the project that produces your framework. Your workspace must contain a target that produces the framework, instead of using a pre-built framework.

您必须已经构建了框架。如果它是iOS框架,则必须为64位运行目标(例如iPhone 5s)构建,并且必须为模拟器构建。

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), and must be built for the Simulator.

您必须拥有一个活动方案,该方案至少构建一个目标(该目标的构建位置将用于操场的框架搜索路径)。

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).

您的构建位置首选项(在Xcode的高级位置设置中)不应设置为旧版。

Your "Build Location" preference (in advanced "Locations" settings of Xcode) should not be set to "Legacy".

如果您的框架不是Swift框架,则定义模块构建设置必须设置为是。

If your framework is not a Swift framework the "Defines Module" build setting must be set to "Yes".

您必须在操场上为框架添加一个import语句。

You must add an import statement to your playground for the framework.

一旦满足所有这些条件,导入框架将在游乐场中运行。

Once all these conditions are fulfilled, importing your framework will work in a playground.

在Xcode 7中,我们引入了另一种可以使用的机制将您自己的类导入为源,而不是导入框架;您可以在 http://help.apple上阅读有关此辅助来源支持的信息。 com / xcode / mac / 8.0 /#/ devfa5bea3af

In Xcode 7 we introduced another mechanism that you can use to import your own classes as source, instead of importing a framework; you can read about this "Auxiliary Sources" support at http://help.apple.com/xcode/mac/8.0/#/devfa5bea3af

这篇关于如何将自己的类从您自己的项目导入Playground的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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