Snippet of the Week: Prototyping Views in Playgrounds

Swift Playgrounds are great and a fantastic tool to prototype and design your views in. But until recently, I’ve only been using them a lot for prototyping algorithms on models, not views, since somehow I could never get Playgrounds to show my views correctly. I’ve figured out the gotcha’s though and wanted to share them with you!

Snippet of the Week: Pinning Views

Sometimes you just need to create AutoLayout constraints in code. Maybe you can’t (or won’t) use Interface Builder. Or you still have to support iOS 8, which means UIStackView is out (though you can use OAStackView if you want). But, handling the NSLayoutConstraint API is pretty cumbersome, especially for seemingly ‘simple’ layouts.

Snippet of the Week: `NSLocalizedString(_:)`

It’s a good habit to start localizing all your user-facing strings from the get-go, even if you’re just tinkering around on a side project. But, while this is a good habit, it riddles your code with strings like these;

Snippet of the Week: `grouped(by:)`

Last holiday, I had the opportunity to start on a new side-project. One of the techniques I touched on, was grouping an array of model objects into sections. Instead of writing my umpteenth for-loop for this, I opted to create a generic function for it.

Thinking up Singletons

While exploring a rescue project, I came across singletons… tons and tons of singletons. There was even a Singletons.swift that just instantiated the lot of them at runtime. Because reasons…