August 10, 2012
Good Friday #1: FTWDevice — UIDevice, but for Macs
This is the first in a series called Good Friday. I’m gonna be open-sourcing a new, (somewhat) cool thing every Friday for the next few weeks.
In building the FTW Mac app, we needed access to some information about each computer that it ran on, so that we could identify it from within games. UIDevice is so handy on iOS, and with Erica Sadun’s UIDevice+Extension, it becomes even better. Instead of writing a couple of little functions to get the MAC address and computer name and model, I sat down and filled in the blanks.
What I ended up with was FTWDevice, and near-perfect drop-in replacement for UIDevice, built for Cocoa on the Mac. Check it out at GitHub: https://github.com/FTW/FTWDevice.
There are a few notes and caveats with it. Because NSHost has
+localizedName, I stuck with those conventions in FTWDevice. This is a little different from UIDevice’s implementation, so be wary of that.
There are a few integer overflow issues with the RAM and hard drive space functions, and I’d appreciate a pull request if you have an idea about how to make that better. Gestalt is also being deprecated in 10.8, so if anyone has a better way of getting the system version, I’d love to hear that as well.
Other than that, use and enjoy! I’d love to hear if you use this anywhere, so make sure to let me know if you find it useful.