MacKuba

🍎 Kuba Suder's blog on Mac & iOS development

The longest names in Cocoa

Categories: Cocoa, iPhone Comments: 7 comments

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).

So here’s what I’ve found:

The longest name in the whole result set

  • cairo_atsui_font_face_create_for_atsu_font_id_REPLACED_BY_cairo_quartz_font_face_create_for_atsu_font_id (104)

This monstrosity was found in cairo-deprecated.h in X11 headers directory. Doesn’t really count as Cocoa though, it wasn’t even written by Apple (it says RedHat in the comments).

The longest names in Apple’s frameworks:

  • kBluetoothAMPManagerCreatePhysicalLinkResponseAMPDisconnectedPhysicalLinkRequestReceived (88)
  • kBluetoothHCIExtendedInquiryResponseDataType128BitServiceClassUUIDsWithMoreAvailable (84)

These were both found inside IOBluetooth.framework. Note to self: don’t try to code anything Bluetooth-related in Cocoa…

Popularity award:

  • __AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5 (83)

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…

7 comments:

J Bryan Price

I found your post after running across

automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers (70)

in UIViewController for iOS 5.

I'm sure glad it's not "autoForward" or something equally obtuse :)

Brent Royal-Gordon

Core Data's support for iCloud adds this monster notification to Cocoa:

NSPersistentStoreDidImportUbiquitousContentChangesNotification (62)

The Apple engineer who discussed it at WWDC (at least during the iOS Core Data session) joked that he had a hard time fitting it on a slide.

nomoral

why, why?
why do they do this to us??

Ramy

In core animation kCAMediaTimingFunctionEaseInEaseOut rofl

Choominator

MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification (74). Do I win this contest?

Kuba

@Choominator: OMG... looks like it's getting worse with every new version...

Marcel Weiher

The problem, of course, is the fact that all of these must be globally scoped, because Apple has forgotten how to use classes for namespacing.

Leave a comment

*

*
This will only be used to display your Gravatar image.

*

What's the name of the base class of all AppKit and UIKit classes?

*