Recently I’ve been poking around a fun little toy in Cocoa called NSOutlineView. You can get some really fancy stuff going on in there. I spent essentially two weeks learning to do drag and drop properly, but something always came up and bit the experience in the rear. My cells would re-arrange themselves during disclosure and selection events.
Berkeley DB FTW
I recently came into contact with a piece of software called Berkeley DB. It’s actually really cool, and I never knew about it! Here’s the story of NSError *, Microsoft Windows Server, and BDB.
Argument Parsing
Writing command-line tools can be a lot of fun, but writing them can be a bit of a pain. The most painful part of this can be argument parsing and validation! I’ve been writing a tool at work which is composed of many sub-commands which each respond to different argument patterns, so I had a lot of redundant code. I refactored for many days and many nights three workdays to create a declarative argument parser. And here’s the story.
Swizzling for Pretty Printing
So after a little bit of thought, I decided to try my hand at method swizzling. So my newest iteration in my implementation of descriptionWithLocale:indent: has me swizzling the Apple-methods away so that it’s as transparent as possible to work with. Now all a custom object has to implement is descriptionWithLocale:indent: and NSContainer objects will honor this (after swizzling). It’s better than a category because it allows you to turn it off whenever you want.
I did keep the fs_descriptionDictionary functionality because I believe that it is a good way to handle things, but it really is optional.
Rake Your Objective-C Life Easier
Rake, or Ruby Make, is a really awesome little tool that you should use to simplify your Objective-C workflows, and I’m going to show you why. You heard me right, fool, show you. Rake can help you build sketches. A sketch is what I call a small program that just proves a point or is just an isolated place that you play with your code. It isn’t big enough to warrant its own Xcode project, but isn’t a single-file that you can easily build by typing compiler commands in all day. More often than not, my sketches involve source files from existing projects. Rather than make a new product in the Xcode project or a new Xcode project, I use Rake to rope in the files and automate the build process.
Pretty-Printing Containers
Yet another random perambulation in the never-ending adventures of myself versus the imaginings of my own mind. Only in this episode, the problem I was tackling was that of NSArray and NSDictionary’s (collectively referred to as NSContainers for brevity’s sake) implementation of descriptionWithLocale:indent:. They are documented to auto-indent any kind of object they contain that implements either descriptionWithLocale: or descriptionWithLocale:indent:, allowing you to have your own objects printed with NSContainers like they’re Apple-code. But they don’t behave that way, and instead newline-escape the description string and print it inline, frustrating me greatly. As I understand it, this is a behavior brought on by the desire to prevent malicious code from doing nasty things to log files. But I still want this behavior. What do to?
URLOperation
So as I’ve been chewing through NewDot and my Discussions application I’ve been developing this class which makes it really easy to queue NSURLRequests in an NSOperationQueue. It’s the kind of utility class that you’d think Apple would have already written, but in their strange land between the comprehensiveness of Ruby’s standard library and the terseness of the STL, it somehow got left out. As well as NSMutableURL. I suppose it’s just left as an exercise to the programmer.
After some thought I’ve decided to tear this class out of NewDot and peddle it as its own reusable component, FSURLOperation. It’s changed a little bit since I was pontificating about SOAPy Spaghetti, so I wanted to blab a bit about it again. Because I honestly think it’s one of the most cool bits of code I’ve written recently, especially because of something I was able to do with it (that’s really related to SOAPy Spaghetti).
SOAPy Spaghetti
For the past several days I’ve been beating through a poorly designed Web Service (WS), trying to write a client for it. What I’ve been using for it is pretty typical: Objective-C, Cocoa, and lots of stress-induced follicle separation. What has resulted is what I’ve begun calling the next iteration of Spaghetti Code.
Matrices in Cocoa
So something that I’ve been thinking about a lot over the past year is arrays in Cocoa. We all know and love the trusty NSArray and its mutable counterpart, NSMutableArray. However, one thing that you can’t (easily) do with them is nest arrays to create multi-dimensional containers. Consider the following:
Thoughts on Block Indentation
So I’ve been working through something recently which looks more or less like the modern equivalent of spaghetti code. Web requests and NSOperations all over the place. It’s certainly a challenge to keep it all straight! But one of the little things that it’s put on the back of my mind lately is something deeply important to all of us: indentation.