Keep calm and open a playground

I realize that “Keep calm and do whatever” has probably been overused at this point and now belongs to the not-so-cool-anymore memes. But then again, this has been my way of tackling a problem, whether complex or not. When I want to try something, I start with a playground.

A folder showing all the playgrounds

I have a “playgrounds” folder that I clean every once in a while, after a quick look at the content of some of those playgrounds. It’s usually a great kick in the butt: “I could have written a post about that!” I got pleasant feedback from a tweet I made about using a playground today to implement a design’s fancy effects on a background image so I figured I should write a post about this tool.

A playground showing how to use blend mode

Playgrounds may seem a bit frustrating to newcomers. It’s not obvious that you can do UI work. It requires importing an XCPlayground framework, creating a view and feeding it to the currentPage… The discoverability of those features is not that great. Unless you bother reading the documentation, that is.

import XCPlayground
import UIKit

let view = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 500, height: 500)))
view.backgroundColor = .redColor()

XCPlaygroundPage.currentPage.liveView = view

The truth is, you can do a lot more than just that: loading custom fonts, trying out autolayout constraints, network calls, even letting users try your 3rd party framework.

A playground showing keep calm and open a playground

I wanted to write a quick post about Playgrounds because, to me, they are a fantastic learning tool, whether you’re learning Swift or trying to tweak a loading animation. Lately, we’ve been seeing more and more people leveraging the power of playgrounds: a ruby tool to generate playgrounds

https://twitter.com/SteveStreza/status/774481522770391042

I’ve grown tired of seeing a lot of negativity against the tools provided by Apple. I figured the best way of fighting against that is to talk about tools that work.

And Xcode playgrounds sure as hell work.