The Good

Build Skills

Swift Playground on the iPad seems to be a good way for a non-programmer to become familiar with simple programming concepts, and write some working code.

It would also be appropriate for someone with some programming skills who wants to become familiar with Swift and with writing code for iOS.

Even for experienced programmers Swift Playground on iPad could be very useful in becoming familiar with iOS programming, and do so without a Mac. The Swift Playground books available with Swift Playground contain a lot of code, much of it is oriented toward graphics and GameKit.

Advanced Concepts Made Easy

But central to the operation of Swift Playground is the inter-process communications facility, XPC Services API, XPC is not just part of Swift Playground, but part of the underlying iOS as well as MacOS. Swift Playground shows its usage throughout the code and makes the basics of using XPC pretty simple.

Teaching Tools

Swift Playground allows you to develop your own “books”. If you are a teacher developing instruction, there are three teachers guides packaged as two iBooks. The first package gets good ratings. The second has no ratings yet. Both are from Apple Education.

  1. Swift Playgrounds: Learn to Code 1 & 2
  2. Swift Playgrounds: Learn to Code 3
Also See

Introducing Swift Playgrounds, video of the session from Apple’s World Wide Developer Conference (WWDC), 2016.

The Bad

Xcode Development

Apple and other documentation mention creating all but the simplest Swift Playground books on a Mac in Xcode.

But it took some digging to discover that Xcode does NOT actually support development of Swift Playground Books. What you can do is edit files on Xcode. But there is no simulator, there is no way at all, to run a book under Xcode. Thus, no debugger. No automated packaging, just highly error prone hand creation (get all the right files in all the right directories). Then AirDrop the “project” (not a project in the Xcode sense) to iPad and see what happens. Iterate.

Development of non-trivial Swift Playground books will be very tedious and error prone until Xcode support is released. It will happen. I expect. I hope.

No Custom Frameworks

In the GitHub repository you can see that the BGL2015 Visualizer demo app ships with two custom frameworks:

  1. BASelectionistNeuralNetwork: The neural network model (78 files containing 5,431 lines of code, as counted by CLOC).
  2. BASimulationFoundation: Small framework library containing support classes (31 files containing 1,939 lines of code, according to CLOC).

Note: the BGL2015_OSX application, which adds the UI, is another 96 files containing 7,582 lines of code)

The expectation in developing a framework is that it can be used on any supported platform more or less just by including it in the project and using “import” statements in each client file to access it.

It appears that Swift Playground does NOT support such custom frameworks. Thus, creating a Swift Playground book that uses the neural net becomes a lot of extra work. The options include:

  1. Include the existing Swift source code in each Playground book. This would require modifying most files to keep their “import” statements from causing the code to fail on Swift Playground. Might not be too bad if Swift has a conditional check that will tell us whether we are running on Swift Playground, rather than just iOS versus MacOS, tvOS, or WatchOS. There may be a way to do it, but I cannot find it.
  2. Create a new version of the source code specifically for Swift Playground. More practical than #1, but creates maintenance issues. Changes to the main framework code will not automatically show up in the separate version for Swift Playground on iPad.
  3. Wait. It is early days for Swift Playground on iPad. I am not the only one finding shortcomings. Future releases will add features that will make it easier to use as a serious tool for tasks other than an intro to Swift programming on iOS (which is an important task in its own right, of course).
Also See

I got excited when I saw the title of this article, but, it just confirmed what I already knew:

Going Forward

Until Swift Playground Book support is a bit more mature (or exists at all) I will develop code for the bio behavioral selectionist neural network  in plain old Swift Playground on Xcode.

Advantages:

  1. Swift Playground is well supported under Xcode.
  2. I can do native Mac development, which means no iOS simulator to slow me down.
  3. I don’t have to do a special version of all code for Swift Playground.
  4. My Mac is much much faster than my iPad (12 cores versus 3).
  5. I can develop for both MacOS and for iOS at the same time in side by side windows.
  6. It will move the Swift Playgrounds on iPad project forward. Pages developed under Xcode can later be incorporated into a Playgrounds Book.