运行 iPad Xcode 中创建的游乐场

Run Playground created in Xcode on iPad

是否可以使用内置传感器在 Xcode 和 运行 中创建游乐场并在 iPad 上创建游乐场并在右侧显示视图(时间轴)屏幕?是否可以在创建 playground 时选择平台 iOS 只是为了测试 iOS 代码?

所以我一直在做一些研究来回答这个问题,但我不能明确地说出它的每一部分。

我能回答的是 运行ning Playgrounds 是在 iPad 上的 Xcode 中创建的可能性,答案是肯定的。我在下面概述了我尝试过的方法,但可能有我遗漏的解决方案,所以请随时贡献。

首先,我在我的 MacBook Air 上安装了 Xcode 8.2.1,这使我能够创建新的 Playgrounds 项目。此外,我还有一个 iPad Air,上面安装了 Swift Playgrounds 应用程序。我相信 Swift Playgrounds 至少需要 iOS 10 至 运行.

我做了一些调查,找到了 Apple Swift Playgrounds 的主页。底部是文字:

Take things to Xcode. Then take them further. Because you’re working with real code, you can import and export directly between Swift Playgrounds and Xcode. So you can try out your ideas with the tool pros use to develop iOS and Mac apps.

我想尝试并弄清楚如何 "import and export directly between Swift Playgrounds and Xcode."

首先,我在 Xcode 中创建了一个新的简单 "Hello World" 游乐场,名为 Test.playground。你可以想象它看起来像下面这样:

import UIKit
print("Hello World")

其次,我使用 AirDrop 将 Test.playground 从我的 MacBook Air 传输到我的 iPad Air。我的 iPad 给了我将其保存到 iCloud Drive 的选项,所以我这样做了。这是一项需要在“设置”中启用的功能。

第三,我在 iPad Air 上启动了 Swift Playgrounds 应用程序。左上角的 + 号允许您 "Create Playground" 或访问 iCloud Drive(或 Dropbox 等)以导入 Playground。我 select 编辑了 iCloud Drive,因为那是我从 MacBook Air 空投 Test.playground 的地方。 iCloud Drive 将有一个文件夹,用于存储名为 "Playgrounds." 的应用程序的所有 Playgrounds 在该文件夹中点击我可以看到我 select 编辑的 Test.playground

一旦你 select 你的游乐场,它应该打开。我能够按 "Run My Code" 并看到 "Hello World" 打印出来。

这就是我弄清楚如何在 Xcode 和 Swift 游乐场(在 iPad 上)之间 import/export 游乐场。我必须进行更多实验以确定两个平台之间 functionality/similarities/differences 的完整范围(运行ning Playgrounds in Xcode 和 Playgrounds in Swift Playgrounds app on iPad).

希望对您有所帮助。