Playing safely in Swift Playgrounds
I almost missed it.
I was so put off by the app's WWDC Keynote introduction and "Learn to Code" content — the hype, the marketing, and the sample content that favored gameification over pedagogy — I almost missed how good Swift Playgrounds is today and how great it can and will be in the near future.
Xcodesploration
I loved Xcode Playgrounds from the moment they were introduced two years ago: They're a perfect way to learn and experiment with Swift code.
Before Xcode Playgrounds existed, if I wanted to teach you to program, we'd have to open Xcode and create a new Single View project. We would look in the App Delegate and look for the method that was called after the app loaded. If you're new to iOS, this is where the questions start: "What's an App Delegate?", "How and when does this method get called?", et cetera, et cetera. It's a lot of cognitive overhead, and we haven't even started coding yet.
Sure, the first version of Playgrounds was flawed; over time, however, it's grown into a great platform for teaching experienced developers how to code in Swift. We can now more easily add documentation to Playgrounds, create multi-page documents, and add source files and resources to individual pages or to the entire Playground. We can even drag colors and images right into the window.
In short, Playgrounds are a great environment for experimenting with code, trying out algorithms, and learning new libraries. The problem is that this runs inside of Xcode. As such, it's difficult for programming newcomers to experiment with this platform without being exposed to more power than they need or can initially handle.
Immersing the learner
There were many developers asking for Xcode to be ported to the iPad; I was not among them. It makes perfect sense to me, however, to bring Playground support to the iPad. Swift Playgrounds gives us this — and does so in a much friendlier way than its Xcode counterpart for new coders.
Master your iPhone in minutes
iMore offers spot-on advice and guidance from our team of experts, with decades of Apple device experience to lean on. Learn more with iMore!
In Swift Playgrounds, we can just jump in and zoom in on the part we want to explain first. When building playgrounds for my students, I can hide all the code I don't want you to think about yet, and include text, glossary items, and hints to help you through the code.
I can also mark some of the code that you do see as un-editable, so that you can't accidentally change code that might make the playground hard to work with. I can even use special commands so that when you tap on any editable code, you'll see a list of allowed elements you can use. You don't even have to type out the element by hand after seeing that pop-up — you can tap on any suggestion and it will automatically drop into the selected location for you.
If the selected field expects a color, a color picker will appear when you tap on it; if it expects an image, an image picker appears. And if you want to dive into more complicated coding expressions, you can also select and use the keyboard.
The key options for Swift Playgrounds are a little different than your standard iOS keyboard: For example, the "=" sign is on the same key as the "d". To select the "=", you hold the "d" down and slide it towards the bottom of the screen. At first this feels awkward, but it becomes second nature surprisingly quickly. You can also use an external keyboard, if you prefer.
Once you've entered the code you want, tap on a button to run the code and see the results. If the results aren't what you expect or want, you can just change the code and press the button again. The learner lives in a protected world that can be focused on the lesson.
Marketing and promise
That said, I'm a bit frustrated with Apple's marketing for this app. Things like "There's never been anything like this" and "Wouldn't this have been cool when we were all learning to code?" are insulting to the wonderful environments that have come before Swift Playgrounds: Turtle Logo and Squeak were available on systems before iOS was ever imagined. In fact, Squeak was originally released by Apple in the 1990s.
The fact that many of these great learning environments aren't available on the iPad is not due to technical reasons — John Macintosh had Squeak running on an iPhone in 2008. But he couldn't widely distribute it because of App Store restrictions. Likewise, Scratch runs on iOS, but because of App Store restrictions, the MIT site's release only runs on a jailbroken phone.
So I ask you ignore the hype from Apple executives, and Apple's messaging on Swift Playgrounds: It is not only for learning to code, and it is definitely not only for kids. It can also provide an environment where educators and authors can lead others through a curriculum that engages students while masking irrelevant complexities.
- In science, there could be Swift Playgrounds that model physics, chemistry, or life sciences and allow students to work through problems and see results in real time.
- A music class could feature Swift Playgrounds that allow students to learn music theory, train their ear for intervals or harmonies, or play software instruments to complete a challenge. Given the first twelve bars of this piece, compose the next four bars that might logically follow.
- A math class could feature Swift Playgrounds that let students touch functions and data and interact with math in a way that is immersive and personal.
- Can you teach people to code with Swift Playgrounds? Absolutely. I just really dislike the "Learn to Code" example. Swift Playgrounds can be used to teach experienced programmers to program and think in Swift and can introduce programming concepts to those new to programming.
The possibilities are endless, and I look forward to seeing what the community comes up with.
Hurdles and challenges
The app has a lot going for it, but I do have a few concerns and quibbles.
Playgrounds, Lessons, Creations, and PowerBooks
First of all, the name "Swift Playgrounds" is unfortunate; I fear many people will confuse Swift Playgrounds with Xcode Playgrounds. On iOS, the app is called Swift Playgrounds, and each document is a playground — or maybe a lesson? It's unclear. The Apple website refers to one of them as a "Lesson" but most often uses the word "Creation." On the Mac, the app is called Xcode, and the document is called a "Playground."
Whatever their name, the documents Swift Playgrounds creates are essentially interactive books with chapters and pages. Apple could have reused the name "PowerBook" to refer to this new kind of content; the file formats for each type of Playground are distinct, the intent is clearly different, and audiences are vastly different. (radar: 27062404)
Bring this version of Playgrounds to the Mac
The Swift Playgrounds app is so good and so different from Xcode Playgrounds that I would love to see a version of Swift Playgrounds that runs on macOS. This way, non-programmers who own a Mac would be able to use the same "Creations" on both platforms without having to dive into Xcode. (radar: 27064067)
More documentation
When it comes to creating new documents inside Swift Playgrounds as an educator, there is currently no documentation on formatting pages. If you're trying to build a new document in Swift Playgrounds and want to figure out how to hide elements, specify code completion, and make code editable, your only resource currently is WWDC Session 408 "Introducing Swift Playgrounds". You can also AirDrop your Swift Playgrounds content on your Mac and open files with a text editor or Xcode, but that's even less helpful. (radar 27080284)
Pay the creators
Unfortunately, educators and content creators can't currently be rewarded for their hard work: There is no way to sell content in Swift Playgrounds, though I hope this changes with the final release of iOS 10.
Imagine the App Store if no one was allowed to charge for apps, have in-app purchases, or support subscriptions — we would not have iOS's rich array of programs and content. There will absolutely be an initial rush to experiment with this new format, but if Apple wants sustained, high-quality contributions from the educational community, they need to let us choose whether or not to charge for these contributions. (radar 27080103)
File everything
If Apple follows the path of Xcode Playgrounds, Swift Playgrounds will improve quickly as the team implements features they already have in mind that just didn't make it into the WWDC release. Swift Playgrounds will get even better as the development team responds to radars from the community as we request support for use cases they may not have considered.
A Swift Future
Remember, it's early days. Swift Playgrounds is a beta product that is only just being played with by people outside of Apple. Once you discard the messaging and the hype, you are still left with a plenty of potential. Also, remember how much Xcode Playgrounds has changed in the short time since its official release: Swift Playgrounds will certainly grow and evolve. And I love the promise of what it will become.
Swift Playgrounds currently only works on the iOS 10 developer and public beta, and only on the iPad. Once you have Swift Playgrounds installed, you can choose to install the currently-featured content, or you can create your own and AirDrop it from your Mac to your iPad.