Kuba Suder's blog on Mac & iOS development

Ever since I started coding in Cocoa, I’ve been wondering what might be the longest name used for any function or constant in the entire API. Cocoa names can get quite long in general, so the longest one should be really ridiculously long… Of course I couldn’t leave it like this and I had to find out what it was :)

I ran a search for *.h files on the whole disk, and I determined that the interesting stuff was either in /Developer or in /System/Library/Frameworks, so I limited the search to these directories only. I passed the list of all header files through a Ruby script that looked for the really long ones and sorted them by length, and then I analyzed the results to find the winners (I decided to divide them into a few categories).

Popularity award:

This award goes to this interesting macro and all its relatives, of which there are many (basically all possible combinations of existing MacOSX versions). These things are just *everywhere*… For the rest of the categories I’m going to ignore these, to make the results more interesting.

The longest names in Cocoa:

It’s hard to tell what exactly counts as Cocoa and what doesn’t, I’ve always thought of Cocoa as a broad term including all of Apple’s MacOSX frameworks. However, if you import <Cocoa/Cocoa.h> in your code, it only includes Foundation, AppKit and CoreData, so I guess technically only these three form the core Cocoa framework.

Here are the winners in this category:

NSAccessibilityLayoutPointForScreenPointParameterizedAttribute (62)

NSAccessibilityScreenPointForLayoutPointParameterizedAttribute (62)

NSAttributedStringEnumerationLongestEffectiveRangeNotRequired (61)

The first two are from NSAccessibility (AppKit), the third one from NSAttributedString (Foundation).

The longest names in UIKit:

delegateTitleForDeleteConfirmationButtonForRowAtIndexPath (57)

This one is defined in the header for UITableView, but it doesn’t appear in any official documentation, so it probably shouldn’t count.

willAnimateSecondHalfOfRotationFromInterfaceOrientation (55)

UIApplicationWillChangeStatusBarOrientationNotification (55)

These two come from UIViewController and UIApplication, and they do appear in the docs.

The longest notification name:

QTCaptureConnectionFormatDescriptionWillChangeNotification (58)

MPMusicPlayerControllerNowPlayingItemDidChangeNotification (58)

Notification names tend to be very long in general, so I thought they deserved their own category. These two come from QTKit and iPhone’s MediaPlayer framework. These two frameworks (and media-related frameworks in general) had a lot of crazy entries in the result list, so I guess they must be not too fun to use…

And the longest notification in Cocoa (AppKit) was this one (from NSTextInputContext.h):

NSTextInputContextKeyboardSelectionDidChangeNotification (56)

So, mystery solved :) Now I can happily go back to Cocoa coding, looking at the names in my code, and knowing it’s not the worst that could have happened…