Cocoa collections, an advisory note

Now that I'm doing actual useful iPhone development work I'm running into a few… shall we call them quirks? Talking about the iPhone specific stuff possibly needs to be [redacted] because of what's known on Twitter as the FUCKING NDA, but I think if something is also part of the OS X libraries then it is fair game. I had cause in my recent application to use a NSDictionary (well a NSMutableDictionary but let's not quibble, shall we?). A NSDictionary is quite straightforward, it stores key-value pairs. Imagine that you have a Person class and you have some other data (not part of the Person directly) that you want to keep on a per-person basis. You might well decide to use a NSDictionary and store (as a value) a NSArray for each Person (as a key). That way you can quickly retrieve the data for any Person. Now the documentation says pretty clearly that it's going to copy the keys but the obvious implication isn't stated: that means you need to implement a copy operator for any class you plan on using as a key. The thing is, nothing tests to make sure you do that. There's not even a warning if you don't but whatever default copy you get won't pass the comparison function. That means you can never say "Give me Bob's data" because the key for "Bob" won't be the same as the "Bob" object you're using. (And as an aside, yes I realize using the entire Person object as the key is slack. This was a temporary thing I was doing just to get the code running. In the particular case the "Person" object only consisted of a NSString anyway, so it wasn't that terrible.) You can happily stuff data in the Dictionary for "Bob" all day long but you'll get a nil when you try to retrieve the data. So. If you're going to use a NSDictionary with custom key classes you'll want to implement the NSCopying protocol. I suspect you want to implement the isEqual message, and the documentation for that also mentions you need to implement hash. It's not that this isn't in the documentation exactly, but it's not front and center. If say you're writing code on your laptop in a car while driving to a Hooters where you plan on drinking a lot of beer. Hypothetically speaking. This is pretty obvious, but I was surprised that I didn't get some sort of compile-time warning or error. Since the fix it make sure that object passed for the key was of a class that implemented NSCopying I still think the compiler could have detected this. (I'll admit it seems a little non-Objective-C-like but in my still newbie opinion Objective-C suffers from two much "try it it a runtime and see if it works" sort of behavior.) But it's just the sort of the thing you need to check yourself.
Read more

Fringe Thoughts

I caught up and watched the premiere and follow-up episode of Fringe. I'm going to go with a minority opinion and say that I like it. I'm not giddy with joy and dancing around the room or anything, but I found more to like than dislike in the first two go-rounds. Before I start talking about the show proper I'd like to comment on two things. First off, I can't quite decide what I think about the 3d text they use to "subtitle" locations. Basically what would normally be a 2d caption (such "Harvard University" or "Baghdad, Iraq") is placed in the scene and sometimes the camera does cutesy things like fly through an O. The word I keep wanting to use is "showy" but at the same time it's just text and thus almost understated. The most noticeable thing of course is that it's just like the Lost title sequence (although that's against a black background and in Fringe it's embedded in the scene). It's the worst example of getting beat across the brow with the J.J. Abrams connection. "This show is just like Lost! Love it! Love it!" The second thing I'd like to mention (or question) is the fact that the commercial breaks say "Fringe will return in 30/60/90 seconds". I assumed it was just a pilot thing, but the second episode did it as well. As a dyed-in-the-wool DVR user I love that. "60 seconds? OK that's 2 skips, plus probably three back-up skips" and beautiful, we're back to the show. But while I love it, I find it hard to believe the show's advertisers care for it. Indeed I had alway assumed that the fact that commercial breaks no-longer line up in nice 30-second chunks was an explicit attempt to make skipping commercials more difficult. But that's all fluff and nonsense. Let's get to the show itself! Most of the critiquing I read on the internet centered on awkward pacing or quasi-goofy science. The first is a fair criticism (but is true of many pilots, and probably of any pilot for a complex show) and the second is I think just goofy. I agree the pacing for the pilot was uneven. I'd even say it suffered from jamming too much stuff into a single episode (even though it was 1:35, instead of just one hour). For example, I think they could have not introduced the evil corporation concept in the pilot and that would have cut out a whole block of exposition. As for the science… I'm not sure what to do with that complaint. The science is plainly and obviously meant to be pulp. They bust out a honest-to-god Mad Scientist(tm) for crying out loud! I enjoyed the silly pulp nature of it all. I never got into the X-Files (blasphemy!), in large part because we were supposed to take it all seriously and I couldn't do it. Fringe is obviously taking on some of the same ground, but giving the his forgotten gothic laboratory with a rusty sensory deprivation tank and a cow changes the flavor. I think people who see it as typical Hollywood pseudo-science (or even worse the Star Trek:TNG technobabble) are missing the point. They aren't trying to be realistic about the science, they are evoking a particular style. I was a bit taken aback that both of the first two episodes were so horror-themed. There's a laundry list of "fringe science" technologies built into the title sequence, I hope it isn't all going to be jaws-dropping off and people having brain-surgery while conscious. I want to see the alternate dimensions and the nanotech and the psychokinesis, and hopefully the next episode won't have another bioweapon project gone amuck angle. I'm deeply suspicious of the "all of this is tied to one secret lab in the 70's and there are two scientists who worked there" plot, and I hope they downplay that over time. They have to walk a balance to keep the Mad Scientist(tm) a required element or he can't be a pain in the ass. On the other hand while I enjoy the whole "Mad Scientist(tm)" idea, he's also a caricature. In fact that's my strongest objection to the show thus far - everybody is straight out of central casting from the Dedicated Federal Agent(tm) to the Evil Corporate CEO(tm) to the Mysterious Taskmaster(tm) and the Misguided Boy Genius Gone Astray(tm). Again, I can forgive those in a pilot - you need to get enough characters sketched in to start the explosions; but if the characters don't evolve soon it will be a problem. Lost can support a few archetypes, but most of the characters are a little more nuanced. Fringe still has some work to do in that department. But I'm willing to watch a few more episodes before that becomes seriously annoying.
Read more

Flip Mino and OS X

I bought Karin a Flip Mino video camera for her birthday. These cameras come with built-in software for editing video on both Windows and OS X, but you don't want to do that. I knew it was a solvable problem, but I wasn't sure exactly what the solution was. After some quick research I have an answer and I'm willing to share :-) The Mino stores its video in as 3ivx encoded MPEG-4 video. Perian supports 3ivx files, along with a lot of other formats. Download Perian, install the preference pane and Quicktime can now playback the 3ivx files. iPhoto and iMovie HD (aka iMovie '06) can both process the files directly with Perian installed. iMovie '08 won't process them without another step to convert the file to DV format, but Karin uses iMovie 06 anyway, and if I was going to start editing video I'd probably buy Final Cut Express. I read on the web that QuickTime Pro and VisualHub can both do the conversion and those are both highly recommended for anybody doing video anyway, so I'd look at one of those if you need iMovie '08 compatibility.
Read more