Note: this post is part of a 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!
We’ve had a little over two weeks to play with the Swift programming
language now, and one sharp edge that keeps coming up is the
language’s inclusion of what they call “optional types”. The vast majority of
Objective-C developers are familiar with the use of
nil to indicate a
nonexistent value, but communicating that kind of information through a
variable’s type is a bit more foreign.
In this post, we’ll have an introductory discussion about how Swift provides optional types, go over a couple of implementation details, and point out a few tough spots in the optional system.Read on →
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!Read on →
This past weekend I found myself in a situation where I would need to export 20 or so Keynote files to PDF. These generated PDFs all needed to have the same export options (no added dates, no presenter notes, etc.), and I really wanted to avoid having to go through all of them manually, clicking all the relevant boxes – which Keynote helpfully resets every time you hit Export.
Thankfully, there’s a (slightly) better way: AppleScript. With a couple hours’ work, I was able to tweak this script to work with the latest version of Keynote (5.3 at time of writing). The results aren’t great – the exported file always ends up in your Documents folder, and I don’t quite trust some of the delay statements – but it gets the job done with little more than a drag & drop.Read on →
I’ve been looking more and more at using AppleScripts in Alfred, my launcher/productivity app for Mac OS X. 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.Read on →
Scala has been a fairly interesting language to me ever since dealing with it a few years ago for a paper on functional programming; when I saw it referenced again recently (in an article about D, of all things), I decided to give it a try. 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?Read on →
Alfred is one of my personal favorite and most-used apps on my Mac, and with the PowerPack, it’s become my primary portal into iTunes as well. (Those of you with Macs but without Alfred are missing out.) However, there remains one big deficiency in Alfred as it ships: there’s no ability to generate a Genius playlist from the currently playing song.Read on →
Working on an iOS contract application the other day, I happened to create a manager class for a data collection. The purpose of the manager was to bundle a table view data source in with other convenience methods for the array being managed (
count, etc.). In the process, I stumbled across a pretty aggressive autocomplete suggestion.