OMQuickHelp plug-in

OMQuickHelp is really cool:

This plugin allows you to use Dash instead of Xcode's own documentation viewer when using option-click (or the equivalent keyboard shortcut) to view the documentation for the selected symbol.

This is much more convenient than the "method-aware" service I provide in AppKiDo. You don't have to select any text — just Option-click anywhere on the symbol you want to look up. To install the plug-in, just build the project and restart Xcode.

If you want the search to be done in AppKiDo instead of Dash, find these lines in OMQuickHelpPlugin.m:

BOOL opened = [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"dash://%@", searchString]]];
if (!opened) {
    return NO;
}

Replace the lines above with these lines:

NSPasteboard *pboard = [NSPasteboard pasteboardWithUniqueName];
 
[pboard declareTypes:@[NSPasteboardTypeString] owner:nil];
[pboard setString:searchString forType:NSPasteboardTypeString];
 
if (!NSPerformService(@"Look Up in AppKiDo", pboard)) {
    return NO;
}

Again, build the plug-in and restart Xcode. Replace "AppKiDo" with "AppKiDo-for-iPhone" if that's your pleasure.

Note that searching with Dash or AppKiDo is not exactly like Xcode's default Option-click behavior. Normally, Xcode shows you the documentation for whatever the compiler thinks the symbol you selected is. This is unambiguous; there is at most one relevant documentation entry. For example, if you Option-click "view" in the following code, you'll see the docs for NSViewController's view method.

// Yes, this is absurd. It's just for purposes of discussion.
[[NSViewController new] view];

Dash and AppKiDo are different in that they do purely substring-based searches, using no semantic information. Searching for "view" in either app will return a whole bunch of results containing "view". You will have to pick through the search results to find the one you want.

It may be worth occasionally picking through multiple search results if this means you can use your preferred search tool. It may even be useful to see the other search results, which may include related symbols you weren't aware of. And you can always use Xcode's Quick Help inspector (Option-Command-2) to see the same documentation that Option-click would normally have shown before you installed OMQuickHelp.

[Edited.]

Disparate types for the same value

I noticed that the "contents" property of SCNMaterialProperty can be any of fivesix things:

  • NSColor
  • NSImage
  • CALayer
  • CGColorRef
  • CGImageRef
  • [Update: Michael Tsai points out that it can also be an NSArray of six images.]

The three classes — NSColor, NSImage, and CALayer — are about as unrelated as you can get within the Cocoa class hierarchy. Their only common ancestor is NSObject. It's true they all implement NSCoding, and two of them implement NSCopying, but these are such common, generic protocols they hardly count as relating the three classes in a meaningful way.

The two CG pointer types — CGColorRef and CGImageRef — are not toll-free bridged to any of the classes, although they are C-based counterparts to NSColor and NSImage.

I wonder if this property sets a record for the greatest number of disparate, specific types a value is allowed to have in Cocoa. I'm talking about formal Objective-C types, disregarding semantics. Offhand I can't think of an example with more than two.

For example, CALayer itself has a "contents" property which can be either a CGImageRef or, as of Mac OS 10.6, an NSImage. Another example is buttons and cells, which at least unofficially allow NSAttributedString for their titles even though the API specifies NSString. (I don't know if this is officially documented.) Bear in mind that NSString and NSAttributedString are not related by inheritance.

Note that in all the examples above, there is only one conceptual "type" for the value in question, whether it's "graphical contents of a rectangle" or simply "a string".

House = Holmes + Jobs

Sometimes the obvious takes a while to dawn on me. When I started watching the TV show "House" I didn't catch on right away that Dr. House is kind of like Sherlock Holmes. For example, he often knows things about people he's just met that seem impossible until he explains them, whereupon they seem elementary. And every episode is structured as a detective story, with Dr. House as the genius detective. Even when I noticed these similarities, I didn't realize how much inspiration "House" takes from Holmes until I looked it up on Wikipedia.

I suspect I'm being slow on the uptake again, but the other day it occurred to me that House has a lot in common with another famous genius: Steve Jobs.

Consider:

Dr. House has a famously abusive managerial style that takes a heavy emotional toll on his subordinates. He's exquisitely attuned to people's weaknesses. He plays hurtful mind games. He pits team members against each other. He barges into rooms and insults people to their faces. [1]

At the same time, House's team is extremely loyal. They are drawn to him by his brilliance and charisma, and by the very fact that he pushes them hard. They accomplish great things with him that they wouldn't be able to anywhere else. House and his team accomplish the impossible, again and again.

One of House's talents is his ability to hire other talented people. He is extremely selective about who he will work with. As self-centered as he is, he would be the first to admit he is not a solo act. He constantly needs ideas from the team to fuel his own brilliance, even as he shoots down those ideas for being "moronic".

House is also selective about the projects he will work on. He will reject all "boring" proposals, and even some interesting ones, to focus on a project that he feels has some special quality. And then he will obsess over that project until he gets it right.

House can be wrong. In fact, he's wrong all the time; that's why the show is an hour long instead of fifteen minutes. When he's wrong he doesn't dwell on trying to prove he was actually right. He simply moves on and ignores any apparent contradiction with what he said before.

All of the above, and more, was true about Steve Jobs.

It seems to me there must be some conscious homage being paid by the creators of "House". It isn't just the Apple products all over the place or the one actual mention of Steve Jobs [2]. It seems to me there is Steve-ness at the show's very core. I can easily picture Hugh Laurie playing basically the same character he plays now, but with Cook, Schiller, Ive, and Forstall around the table instead of Chase, Taub, 13, and Foreman.

Heck, House shows up for work every day in jeans and running shoes. How much more "Steve" can you get?


[1] Regarding the abusive managerial style, I don't know if Jobs behaved quite as badly when he returned to Apple — indications are that he became a much nicer human being — but certainly the stories told about his early days at Apple and at NeXT are House-like.

[2] "Either that costs more than 25 bucks, or I'm seriously starting to doubt Steve Jobs' business strategy." (Episode 410, "It's a Wonderful Lie")

Scene Kit sample code

I just found out from Peter Hosey that sample code for Scene Kit is publicly available. There are three example projects:

  • Scene Kit Document Viewer
    • Shows basic features of SCNView.
    • Demonstrates hit testing. When you click on an object in the scene, the object is highlighted with a pulsating blue glow.
    • Demonstrates SCNView's built-in ability to pan, zoom, and rotate the scene in response to dragging the mouse.
    • Subclass of SCNView allows you to drag and drop an arbitrary .dae file into the scene view.
    • This is the project I referred to in my earlier post about redistributing Apple's sample code. This public version of the project is different in some minor but noticeable ways from the version I mentioned, which is behind a developer login.
  • Scene Kit Animations
    • Shows how to apply different animations to a scene.
    • Displays a row of buttons for selecting which animation to apply. I found that these buttons were hidden behind the scene view, and I had to rearrange things in the nib to make the buttons visible. I've reported this as rdar://12082268.
  • Scene Kit Material Editor
    • Shows how to fiddle with materials.
    • Provides a UI for tweaking attributes of materials and applying the materials to different shapes.
    • Also shows how to create simple 3D shapes programmatically — something I happened to be wondering about.

These projects all use modern Xcode stuff like ARC, collection literals, and (in two of the three) Auto Layout. Note that Scene Kit requires Mountain Lion.

As of this moment, Googling for "scene kit sample code site:developer.apple.com" still doesn't find these examples, which I find odd, since they've been available for a good ten days. The Scene Kit API docs don't point to the examples yet, but this is less surprising; I'm sure the docs will be updated in good time.

A quick way to find these examples is by going to the Mac Developer Library and entering "scene kit sample code" in the search field next to where it says "Documents" (not the field at the top right corner of the page). Using "sample code" in the search terms is a good way in general to find example projects.

Scene Kit sample code