4

While I'm exploring Playground Book sample code, like this one, I find it to be very tedious to get the code to run because of Playground Book's limitations in where the code can run: only on iPad's Swift Playground.

There is no way to debug the "Sources" / Auxiliary code in iOS's Swift Playground, since all the source files are shown in un-editable plain text. You have to open the source files in Xcode to edit them, but then you can't compile or run them!

This is especially tedious for the sample code above, which uses PlaygroundValue, a persistence API that requires Playground Book format, so I still couldn't get the code to run by separating all source code into a separate Playground file to run on the Mac.

Since the sample code above is outdated, I find it to be near impossible to debug it right and get the code to run. You'd have to:

  • Deploy the code on iPad. Run the Book.
  • See many error messages on iPad.
  • Go back to Xcode on Mac and debug them one by one, manually.
  • Deploy the code on iPad again to run. Repeat the process.
  • Even after all the errors are resolved, you can still be faced with cryptic "Problem Running Playground" without any further concrete explanation.

enter image description here enter image description here

What's your workflow to productively debug and deploy code with Playground Book? Current workflow seems impractical to me I think there must be a better way, but I'm not familiar enough with Playground Book and my online research doesn't yield any reasonable workarounds.

HuaTham
  • 7,486
  • 5
  • 31
  • 50

2 Answers2

3

From a bug report / suggestion I sent to Apple, I got the following reply:

We’ve actually built tools to help debug the auxilliary sources and we did a presentation at WWDC 2018 that demonstrates it. Please view the presentation and get access to the tools here: https://developer.apple.com/videos/play/wwdc2018/413/

Upon further research, I found that they have recently released a Playgrounds Author Template:

The Swift Playgrounds Author Template is a starter Xcode project that will help you create, debug, and produce a Playground book. Using the template you can step through the code for your live view as if it were an app so that you can identify bugs more easily and develop an efficient workflow for developing your Playground books.

This template, requiring Swift 4.1 to run, includes three different targets:

  • PlaygroundBook
  • Book_Sources
  • LiveViewTestApp

enter image description here

You can use the LiveViewTestApp to fully debug your Playground Book right on your Mac with Xcode.

HuaTham
  • 7,486
  • 5
  • 31
  • 50
0

I am not aware of any possibility that does not require you to test the Playground on an actual iPad. Anyway, you can make developing Swift Playgrounds less tedious by

  1. Using iCloud to synchronize your mac version with the iPad.
  2. Embedding your Playground in an Xcode project as described in one of my previous answers. That way, you can at least achieve autocompletion during development.
  3. Linking your source files to another target, so that compile errors can be caught before running the Playground.

Anyway, you will still encounter mysterious "Problem Running Playground" errors from time to time

jraufeisen
  • 3,005
  • 7
  • 27
  • 43