I have to call it a day, but I’m really happy with what I’ve learned about authoring Playground Books for iOS today. (I’m less happy learning about how to completely reset Xcode — either reboot your system or hop into terminal, do a ps -ax and grep for Xcode and then kill anything with the name in it.) I thought I’d share a few lessons.
If you are going to author for iOS, start with a new playground created from scratch in Xcode 8 rather than modifying an existing one. If you cannot import PlaygroundSupport, reboot your computer. If it doesn’t show up and you’re still using XCPlayground (now deprecated), you’re doing it wrong.
Understand that the Swift snapshot on iOS 10 is older than the Swift snapshot in Xcode so don’t expect to use really recent evolution implementations:
I ended up implementing my own sequence functions to make my code work.
The easiest way to get started is just to AirDrop a normal playground.
It will open automagically in Playgrounds for you. When you transfer books, you have to choose “open in Playgrounds” from the AirDrop menu.
If you want to author a Playgrounds Book before tomorrow’s session, just customize a blank document (download at your own risk). My blank book is a one-pager, and you can tweak the Contents.swift file in Blank.playgroundbook/Contents/Chapters/Document1.playgroundchapter/Pages/Blank.playgroundpage. There are manifests at every point along the way, try not to mess them up otherwise the book won’t open.
When authoring pages, either in a normal playground or playground book, you can annotate them to omit details that would otherwise clutter the interaction space or should not be visible to the reader. In my Spirograph playground (download at your own risk), I use special mix of normal playground markup (I have a couple of books that cover this markup format: my Doc Markup book and my Playgrounds book) and these new keywords:
- Use
#-hidden-code
and#-end-hidden-code
to exclude code from the reader’s view. - Mark editable areas with
#-editable-code
and#-end-editable-code
, and if you like you can add a note to the opening tag. - To simplify code completion, you can globally omit code completion
#-code-completion(everything, hide)
and then choose which selectors to present, as I do in the following sample. You see this in the above screenshot, which offers one-tap access to just three customization points for my spirograph.
/*: **Spirograph:** Play around. - Note: The default values are: * minor: -3.0 * offset: 130.0 * color: .black() */ //#-hidden-code import UIKit import PlaygroundSupport public var color = UIColor.black() public var minor = -2.0 public var offset = 130.0 public func setMinor(_ value: Double) { minor = value } public func setColor(_ value: UIColor) { color = value } public func setOffset(_ value: Double) { offset = value } //#-end-hidden-code //#-code-completion(everything, hide) //#-code-completion(identifier, show, setColor(_:), setMinor(_:), setOffset(_:)) //#-editable-code Tap to enter code setMinor(-3.0) setColor(.black()) setOffset(130.0) //#-end-editable-code //#-hidden-code let liveView = UIImageView(600, 600, backgroundColor: .white()) PlaygroundPage.current.liveView = liveView liveView.image = spiroImage( size: CGSize(width: 600.0, height: 600.0), samples: 4096, minor: minor, offset: offset, color: color) //#-end-hidden-code