June 2, 2014

Learning Swift: Ordered Dictionaries

Note: this post begins a new series about the Swift programming language, introduced at WWDC 2014. I’m no more experienced in Swift than anyone else outside Apple, but I learn best by coding and talking through a problem. If there’s a better way to approach some of these topics, get in touch on Twitter!

An ordered dictionary is a useful data structure that combines attributes of an array and a dictionary. Like an array, it stores elements in the order they’re added, and enumeration happens in the same fixed order every time. It also satisfies the basic idea of a dictionary: it stores key-value pairs, and can look up values by key.

Ordered dictionaries are incredibly useful tools for all kinds of development. To crib an example from the Swift book, an ordered dictionary might help an app display people and their ages: you might use names for keys, ages for values, and use the order to provide data in table cells by index path (and support user-driven reordering, to boot).

In this article, we’ll build an ordered dictionary atop the two primitive collection types already in Swift: an Array and a Dictionary. Let’s go!

May 28, 2013

AppleScripting Keynote PDF export

This past weekend I found myself in a situation where I would need to export 20 or so Keynote files to PDF ... and I really wanted to avoid having to go through all of them manually. More
July 16, 2012

Audible fun with Alfred

Today's snippet is about switching the active audio output device; I wanted this for work, where I switch between external speakers and some headphones plugged into the front 3.5mm jack. More
May 24, 2012

Bukkit can hold Scala!

Scala is notable for being runnable on the JVM, with the right libraries - and what better way could there be to learn a JVM-compatible language than to write a Bukkit plugin with it? More