Digging Into the Objective-C Runtime

Photo of dog digging by jettef on Flickr

Greg Parker recently tweeted a link to fantastic site he created, An Illustrated History of objc_msgSend, that provides a trip through history of one of the likely most often called, but unheard of functions in iOS or OS X, objc_msgSend. The function dates back to NeXT and the origins of Mac OS and iOS. It’s interesting to see how it has evolved through the versions of the OS, the transitions between processor architectures, and how priorities in the algorithm have changed as hardware has. It was the underpinning of the Objective-C runtime back on those first PowerPC based Macs and still is today on the latest A7 based iOS devices. Incredible.

If you want to learn more about the Objective-C runtime it’s actually open source and is available from Apple’s open source site at objc4-555.1. To go along with the source Apple provides the Objective-C Runtime Programming Guide and Objective-C Runtime Reference. Definitely read through these and take the time to learn more about how the runtime and your modern Objective-C code are related.

Outside of Apple’s documentation, perhaps the best series of posts on the Objective-C runtime and how you can use it are by Mike Ash. Despite the fact that they date back to 2009 and 2010, they’re still very relevant today.

Finally, if you’re looking to do some hacking on the runtime itself, or experiment with patterns and practices from other languages check out libextobjc by Justin Spahr-Summers, one of the Mac developers at GitHub.

Thanks again to Greg Parker for the retrospective, his time spent hacking away on the runtime, and for the inspiration for this post!

Skipping the WebKit cache

Image of Elephants by Mylon Ollila on Unsplash

Caches in WebKit are tenacious. That’s problematic in an app that uses an embedded WebKit view when you’re trying to load your latest JavaScript or CSS changes without restarting the application. Chrome and Safari both provide developer tools for clearing and disabling caches, so I assumed it would be relatively straight-forward to implement a similar option in a custom app.

It was not. There are various methods that should disable or empty the caches, but at least in a Cocoa app with an embedded WebView running in OS X 10.8.5, most of them don’t work.


Barista: a New Embedded Web Server for Objective-C

I came across a new and interesting open source embeddable web server written in Objective-C for Mac and iOS apps called Barista. It’s inspired by the Express web application framework for Node.js and allows you to compose a processing pipeline by connecting middleware components that operate on the HTTP requests and responses being handled by the server. The framework is being developed by Steve Streza, formerly of Pocket, now gone indie and having also recently released Ohai. It’s early days for the project, could use some help, but is definitely interesting and worth a look.


Found on GitHub: PrettyTimestamps

Image of GitHub OctoCat Logo

Jon Hocking recently released a simple category on NSDate that generates relative timestamps such as "3 hours ago" or "2 days ago" from an NSDate instance.

The code is available on GitHub at jonhocking/PrettyTimestamp and is available as a CocoaPod as well.

I’ve put together an example project to demo how the code works at stevenhuey/PrettyDates. It makes use of CocoaPods to manage dependencies so make sure to use the .xcworkspace file and run:

pod install

before trying to build and run the app.

When you save yourself some time generating some nice relative timestamps in your next app make sure give @jonhocking a mention on Twitter.

Alternatives to Apple’s iCloud Core Data Syncing

iCloud_Photos_iPhone4s_iPad_MBP15inch_PRINTIt’s no secret that Apple’s implementation of iCloud syncing for Core Data has issues. Check out episode 12 of Debug for a great discussion and check out the show notes for a number of links to blogs that go into even more detail.

With WWDC around the corner, we can hope for some fixes in iOS 7 and OS X 10.9, but until then a few interesting alternatives have been released. Here’s a look at four of the most promising frameworks for syncing your app’s data.