November 13, 2017

Xcoders talk: Objective-C Bridging

As Swift enters its fourth year in public and continues to evolve, it becomes more and more attractive to add new features using the language — but for those of us who are blessed with large legacy codebases, crossing the divide between Objective-C and Swift can be a burden. What’s more, some of the language features in Objective-C that can help ease this transition aren’t necessarily well-documented or publicized.

This is an issue I’ve been grappling with in different projects for some time, and so when the opportunity arose to discuss the topic at our local Xcoders meetup, I took it. I think this talk had the fewest slides of any presentation I’ve ever given, so I won’t reproduce them here, but the example project is available on GitHub — both before and after the changes from the talk. (A video is forthcoming.)

More
August 31, 2017

Swift Tricks: Emoji Flags

Toying around with some code on the bus this morning, I came across an interesting fact about region flag emoji. Among the thousands of emoji that the Unicode standard defines, 270 of them represent region flags, each corresponding to a two-character region code: “us” means 🇺🇸, for example.

My curiosity was this: is there a way to programmatically generate the flag emoji 🇺🇸 from the string "us"? I was afraid that, like many other emoji, the flags would each have a unique name — something like REGIONAL FLAG UNITED STATES — and would require a lookup table to translate between the basic string "us" and the resulting emoji. Not so!

More
April 2, 2017

Putting Core Data on the Map

Core Data is a powerful framework for all kinds of data persistence, and its NSFetchedResultsController is a key class in many an app. However, its API – especially its delegate protocol – is aimed mostly at table views, and can be a little difficult to connect to other UI classes.

In this post, I’ll walk through the process of hooking up a Core Data stack to an MKMapView. While mostly straightforward to display NSManagedObject instances on a map, there are a few tricks to building a solid app and keeping your map data up to date.

More
November 26, 2015

Variable Capture and Loops in Go vs. Swift

Over the last few months, I’ve had cause to switch between writing app code – largely in Swift – and server code, almost entirely in Go. While the two languages are pretty different, on occasion I’ll stumble across a similarity that seems like it can ease the transition or lessen the learning curve.

This is a story of how one of those similarities was subtly but deeply misleading, and introduced a major bug in a Go application.

More