iOS Playgrounds

Screen Shot 2016-06-13 at 4.59.35 PM

Really early days:

  • App is baked into iOS 10. Just install a beta to your favorite (newerish) iPad.
  • Houdah’s Type2Phone is the best for working with iOS playgrounds. Really great for copy/pasting.
  • Some (but not all) Emacs keybindings work, which makes editing much easier. However, ^A/^E don’t respect the onscreen folding, so in squish mode, they’ll jump to the start and end of each \n-delineated line, not the folded version.
  • I can’t figure out how to get things onto and off of the iPad: tried emailing playgrounds, playground pages, tried going through iTunes, looked in Xcode, even used PhoneView (Ecamm) and iBrowser (my little hack app) to try to track this stuff down. No luck so far.
  • XCPlayground seems to be PlaygroundSupport — took me forever to figure that out because it’s still XCPlayground on the desktop. And of course, all the new ObjC name import stuff isn’t working as expecting, so you do have to hunt around. Live views are PlaygroundPage.current.liveView assignments.
  • To see both code and live view (or just live view), slide from the right.

Lots still to explore!



  • Nice example, but in Swift 3 I was not able to reproduce changing the border color of the frame.

    let view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 200))

    view.backgroundColor =
    // there is no borderColor attribute
    // there is no borderWidth attribute
    // there is no cornerRadius attribute
    import PlaygroundSupport
    PlaygroundPage.current.liveView = view

    • borderColor, etc, are layer properties. I use a convenience function. This one reflects the latest version of Swift 3:

      public extension UIView {
          public convenience init(
              _ w: CGFloat,
              _ h: CGFloat,
              position: CGPoint = .zero,
              backgroundColor: UIColor = .white,
              translucency alpha: CGFloat = 1.0,
              borderWidth: CGFloat = 0.0,
              borderColor: UIColor = .black,
              cornerRadius: CGFloat = 0.0
              self.init(frame: CGRect(x: position.x, y: position.y, width: w, height: h))
              self.backgroundColor = backgroundColor.withAlphaComponent(alpha)
              self.layer.borderWidth = borderWidth
              self.layer.borderColor = borderColor.cgColor
              self.layer.cornerRadius = cornerRadius
              self.translatesAutoresizingMaskIntoConstraints = false
              self.contentMode = .scaleAspectFit
              self.clipsToBounds = true