App idea: extract method name from selected text

This is an idea for a Service (as in the Services menu) to help Objective-C programmers.

Often I'm looking at a method declaration or method invocation and I'd like to be able to copy and paste just the method name and not any of the arguments.

For example, say I'm looking at a method declaration like this:

- (void)putBook:(NSString *)theBookName
      inSection:(NSString *)theSectionName
      ofLibrary:(NSString *)theLibraryName
         inCity:(NSString *)theCityName;

…or a method invocation like this:

[masterLibrarian putBook:@"The Dark Knight"
               inSection:@"Graphic Novels"
               ofLibrary:@"Mid-Manhattan Branch"
                  inCity:@"New York City"];

I'd like to be able to select either of these code snippets and invoke a Service that puts "putBook:inSection:ofLibrary:inCity:" into my pasteboard. Ideally, my selection could be sloppy at the beginning and end, so I could select:

             ian putBook:@"The Dark Knight"
               inSection:@"Graphic Novels"
               ofLibrary:@"Mid-Manhattan Branch"
                  inCity:@"Ne

…and the Service would know what I mean.

Lately I've been running into situations like the above pretty frequently. One case is when I'm writing a method comment:

/*!
 * @method      putBook:inSection:ofLibrary:inCity:
 * @discussion  Blah blah blah...
 */

Another case is when I'm studying someone else's code and I'm taking notes about how a group of classes interact:

Upon receiving the XXBookDidGetClassified notification, we send a putBook:inSection:ofLibrary:inCity: message to the Librarian object and commit the change to the database.

I can imagine other uses as well — for example, selecting a fragment of code in a cocoa-dev email and pasting the method name into either Xcode's or AppKiDo's search field.

It would be nice if code completion could help here, but code completion in comments only completes the first word in a method name, without the colon — i.e., "putBook" in the example above. (I just filed rdar://7197881 about this.) Also, code completion only works in Xcode, and I use TextWrangler to edit notes that are not in the code.

Another way to do this would be to click anywhere in the method name and bring up the Refactoring window, which has the method name already selected and ready to copy to the pasteboard. But this adds two keystrokes — one to open the Refactoring window and one to close it — plus a moment's delay before the window appears. And this only works if I'm looking at the code in Xcode.

Come to think of it, if Xcode can populate that field in the Refactoring window, it can just as easily put the method name into my pasteboard. It could provide this functionality in a Service as well, so I'd be able to use it when I select code in a cocoa-dev message, for example, or on a web page. I just filed rdar://7198039 asking for this.

How to update your developer docs

Apple used to bundle developer documentation with releases of Xcode, but as the docs started to get updated more frequently, it made more sense to have us download them separately. This means that when you install Xcode for the first time, you do not yet have a local copy of the docs. You have to go get them.

The way you install or update your docs depends on which version of Xcode you're using:

  • If you're using Xcode 3.2, go to the Documentation pane of the Preferences panel.
  • If you're using Xcode 3.1.x, go to the Documentation window, which you can open from the Help menu. If there's an "Update" or "Subscribe" button next to the Core Library docset, click it. Otherwise, use the gear menu in the lower left corner to manually update the docset.
  • If you're using Xcode 2.5, this bug doesn't affect you, but it's a good idea to keep your docs up to date anyway. As in 3.2, go to Preferences -> Documentation. Make sure to restart AppKiDo so it can reparse the docs.
  • If you're using an Xcode older than 2.5, you should really, really upgrade.

Peter Hosey describes a way to get the docs using RSS, which you might prefer for one reason or another. Come to think of it, I might find this useful for archiving past releases of the docs, for testing AppKiDo with.

How to stop AppKiDo 0.983 from crashing on launch

If AppKiDo 0.983 is crashing on launch, try going into Xcode and updating the Leopard Core Library docset. If it's the same problem a couple of people have reported, the crashing should go away. If you're not sure how to update the docset, see my next post.

(Note this is not a problem for AppKiDo-for-iPhone, so if that's crashing for you please let me know.)

Here's what was causing the crash. During startup, AppKiDo reads a property called "DocSetPlatformVersion" from a plist file in the Cocoa docset bundle. There was at least one version of the docs where that value was missing from the plist, and since I don't check for this, I ended up trying to insert nil into an array. Updating your docs gets rid of the crash by fixing the plist.

Yeah, I shouldn't be hacking around in undocumented plists (setting aside the more grievous error of not checking for nil), but the fact is that AppKiDo relies almost totally on undocumented file, directory, and database structures. There are ways I can reduce this dependency (especially when I get around to requiring Xcode 3 as a minimum), but I don't see the hackishness going completely away any time soon.

At some point I'll release an update to handle situations like this more gracefully.

Thanks to Chris Backas for helping to track this down.

Crashing bug in 0.983

I should probably have released one more sneakypeek before pushing 0.983. I've gotten a couple of reports of a crash on launch. Haven't found the problem yet, but it's totally reproducible, the stack traces look the same, and it's almost certainly a dumb error I could have caught by programming more defensively. On my list for the next minor release: more robust and informative error handling.

(The next major release, where I get rid of the long launch, is still a long ways away.)

UPDATE: Found it.

AppKiDo 0.983 works with Snow Leopard

Yeah, it would have been better to release this in time for folks to use it with Snow Leopard seeds.

http://appkido.com/release-notes.html

  • Works with the Xcode 3.2 docs (i.e., Snow Leopard).
  • Added NSDate to the "Strings, data, collections" quicklist.
  • If you switch to a different app while AppKiDo is loading, you won't get AppKiDo windows popping up in front when it's done loading.
  • Changed to look for docs in the right place when the Dev Tools version is 2.5 and the Dev Tools directory is not /Developer.
  • Added a popup button in prefs so you can choose between iPhone SDKs if you have more than one installed.
  • Fixed bug where links to http: pages (like the sample code links in +stringWithString:) weren't going anywhere.
  • Fixed bug causing DOM classes to show up as root classes.
  • When you do a search, jumps to the first search result that has the search string as a prefix, if there is one.
  • Staggers placement of new windows.

UPDATE: Corrected the link for downloading the source.