NSPasteboard and Dynamic UTIs

When dealing with pasted or dragged data in Cocoa, we receive the passed data on an NSPasteboard. Prior to v10.6 (Snow Leopard), this pasteboard could only contain a single item, but now it can contain multiple items, which are returned as an NSArray via the -pasteboardItems method.

The data passed in via the pasteboard can be in a variety of types (for instance, a single image could be passed both in JPEG format and TIFF format), and for compatibility reasons these types can be expressed in various ways—they can be MIME types, UTIs, OSTypes, or PboardTypes.

If we want to handle pastes and drags in the proper, modern, multi-item fashion, you’d think we could just iterate over the -pasteboardItems (each is an NSPasteboardItem), ask each for its -types, and handle the data in our preferred format. Unfortunately things aren’t always that simple.

Interface Builder: Objects-Under-Mouse Menu

For those annoying times when you’re trying to select a particular object in Interface Builder and you keep getting an item above or below it (NSTableView, anyone?), try this: Control-Shift-Click to display a pop-up menu of all the items under the mouse.

Copy, Don't Retain NSString Properties

In general, @properties of type NSString* should be copied, not retained: @interface SomeClass : NSObject @property (nonatomic, copy) NSString* someText; @end The reasoning behind this is that because NSString is a class cluster, what appears to be an NSString could really be an NSMutableString, and thus could change behind your back—generally not something you want. However, if you specify copy then the instance of SomeClass will have it’s own unique copy of the original string.

First Post

Welcome to my new scratchpad for posting programming tips, gotchas, best practices, and revelations. I’m not intending to focus on production value but rather on jotting down things I’ve learned. I’m mostly working with Objective-C on iOS these days, so that will comprise the majority of the content. Happy hacking.

Focusing, Shuffling

I’m doing a bit of work to get things better organized around here. I have the both fortunate and unfortunate affliction of having far too many interests—the harm in this is that if I blog about what’s on my mind, there’s no way anyone else will actually want to follow along. From here on, this blog is going to focus on lifehacking, location-independence, and entrepreneurism. It’s about embracing your passions, eschewing societal standards, and living an awesome life.

Dreams, A Personal Insanity

1. It was kind of my friends to throw me a surprise party, but the jovial mood was tainted by the presence of my nemesis. I knew this stout black man from his neighborhood pool cleaning service but apparently he moonlighted as a cake baker. And tonight, not only was he baking my cake, he was extorting six dollars from me for a cake pedestal–whatever that was. Ah well–I brushed it off and returned to the party, replete with champagne and cubic leather ottoman.

2010 Plan & Goals

Yeah, sure, New Year’s resolutions, fine. Well I sort of missed it, so I gave myself until the end of January to plot my year. I generally wanted to embrace the S.M.A.R.T. (Specific, Measurable, Attainable, Realistic, Timely) goal-setting concept where possible and practical, so what’s below is divided into the discrete, check-it-off-when-done tasks, and the more abstract goals I’ve haven’t wrangled into task form (or don’t want to take the time to track, like some of the dailies).

Questions About the Apple iPad

Well, the Apple tablet, the “iPad” was just announced. I was fairly accurate with my predictions for the device: 9.6 in. screen, 3G internet connection, $499 price tag. Now that we have the details we’re left wondering how this fits into our repertoire of technological devices. What can it do for me? Developers seem to be on the fence. For the most part we’re thinking it’s too phone-like to replace our laptops, and too big to be a phone—why would I shell out $500?

2009: A Year in Review

When I sat down to write this I was convinced that 2009 was a fairly crappy year. I feel like I spent about half the year blocked by circumstance from doing the things I really wanted to do. But after compiling a list of how I actually spent my time I realize that while it wasn’t everything I hoped it could be it, it was still pretty freaking cool. Here’s a list of some of the more interesting occurrences of 2009:

Lifehacking, Expanded

(Photo: left-hand) My friend Richard recently commented to me how curious it is that people alive today know little more about how to be human than the people who came before us. It’s an interesting point. Sure, we have an increased understanding of the physical world, but there’s no state-of-the-art for how to conduct our daily activities. Collectively, we don’t seem to be progressing on this most basic front.