Over at the Big Nerd Ranch blog, my friend Mark Dalrymple continues his “Inside the Bracket” series with an article on practical uses of Objective-C’s run time introspection.
Last time you saw the parts of the Objective-C runtime API that let you query a bunch of the metadata the compiler keeps around once it’s done building your project. Like most discussions of API, it was pretty abstract. “Look at all the pretty tools! Ooh, we can print out Lists of Stuff! Isn’t that amazing!”
This time around is an actual application of this API for Great Justice. I was working on a client project that consumed blobs of JSON data from a third-party web service.
Converting JSON to Objective-C objects is fraught with some peril, but with the code Mark presents it becomes a lot safer.
Mark’s code, incidentally, is an improved version of some code I wrote and discussed on Cocoa is My Girlfriend. Mark’s version is better, though.