Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Playground created in Xcode on iPad

Is it possible to create a playground in Xcode and run that playground on an iPad using the built in sensors and showing the view (timeline) on the right side of the screen? Is the possibility of selecting the platform iOS when you create a playground just for testing iOS code?

like image 634
Lenny1357 Avatar asked Mar 09 '23 16:03

Lenny1357


1 Answers

So I've been doing a bit of research to answer this question and I cannot definitively say for certain each part of it.

What I can answer is the possibility of running Playgrounds that were created in Xcode on iPad and the answer is yes. I outline below what I tried but there may be solutions out there I'm missing so please feel free to contribute.

To begin with, I have Xcode 8.2.1 installed on my MacBook Air which enables me to create new Playgrounds projects. Additionally, I have an iPad Air with the Swift Playgrounds app installed on it. I believe Swift Playgrounds requires at least iOS 10 to run.

I did some research and found the main page for Apple Swift Playgrounds. At the bottom is text that reads:

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.

I wanted to experiment and figure out how to "import and export directly between Swift Playgrounds and Xcode."

First, I created a new simple "Hello World" Playground in Xcode called Test.playground. You can imagine it would look like the following:

import UIKit
print("Hello World")

Second, I used AirDrop to transfer the Test.playground from my MacBook Air to my iPad Air. My iPad gave me the option to save it to iCloud Drive so I did. This is a feature that needs to be enabled in Settings.

Third, I launched the Swift Playgrounds app on my iPad Air. The + sign at the top left allows you to "Create Playground" or access iCloud Drive (or Dropbox, etc) to import a Playground. I selected iCloud Drive since that is where I AirDropped my Test.playground from my MacBook Air. iCloud Drive will have a folder that stores all the Playgrounds for the app called, "Playgrounds." Tapping inside that folder I could see my Test.playground which I selected.

Once you select your Playground, it should open up. I was able to press "Run My Code" and see "Hello World" printed out.

And that's about as far as I got in figuring out how to import/export Playgrounds between Xcode and Swift Playgrounds (on iPad). I have to experiment more to determine the full scope of functionality/similarities/differences between the two platforms (running Playgrounds in Xcode and Playgrounds in the Swift Playgrounds app on iPad).

I hope this helps a little.

like image 131
schifano Avatar answered Mar 21 '23 05:03

schifano