Mining for API trivia

On Twitter, Peter Hosey wondered what is the longest public symbol name other than a selector in Apple’s APIs.

@Bavarious and Ken Ferry both found kCMSampleBufferConduitNotificationParameter_UpcomingOutputPTSRangeMayOverlapQueuedOutputPTSRange (96), which was announced in the release notes for OS X 10.7 and iOS 4.3, although it isn't documented otherwise. I've submitted feedback to Apple about the missing documentation.

Here's how @Bavarious found it:

Ken also shared the method he used. If you don't use the fish shell, here's a minor variation of Ken's commands that works in bash:

cd /System/Library/Frameworks/

ls /System/Library/Frameworks | perl -ple 's/(.*).framework/$1.framework\/$1/'  | xargs  nm  | perl -nle 'if (/([A-Z]\s.*)/) { $len = length($1); print "$len $1"; }' | grep -v ":" | grep -v ZN | sort -n | grep -v "install_name" | grep -v "OBJC_IVAR"

To find the longest symbol that's not only public but whose meaning is documented, I poked around in the innards of Apple's docsets. Focusing first on iOS, I ran this command in Terminal:

sqlite3 ~/Library/Developer/Shared/Documentation/DocSets/

In the past I used to operate on a copy of the docSet.dsidx file, out of nervousness that I'd accidentally modify it. I don't bother making a copy any more, because I'm unlikely to accidentally perform an UPDATE or DELETE, and because in the worst case I can delete the docset and re-install it.

The dsidx file is a Core Data store containing information about API symbols and where they are documented. Each symbol has a token type indicating whether it's a class name, a macro name, etc.:

sqlite> .headers on
sqlite> select * from ztokentype;


Here is a SELECT statement that finds the longest documented symbols in iOS 6.1 that are not selectors:

sqlite> select ztokenname, length(ztokenname) length, ztypename from ztoken, ztokentype where ztoken.ztokentype = ztokentype.z_pk and ztypename not in ("clm", "instm", "intfcm", "intfm") order by length desc limit 5;


The same technique applied to the 10.8 docset reveals the function name IOBluetoothOBEXSessionCreateWithIOBluetoothDeviceRefAndChannelNumber. Its length is only 68, so iOS wins with MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification (74), assuming there isn't an error in the database or in my admittedly shaky SQL.

Note that the contents of the ztokentype table are different in the OS X docsets than they are in the iOS docsets, so if you experiment with the SQL commands above you may have to adjust your "ztypename in …" or "ztypename not in …" clauses accordingly.

UPDATE 1: I thought @Bavarious and Ken Ferry had found two different symbols, but as Ken explained to me, they had really found the same one. I rewrote the relevant parts to reflect my better understanding.

UPDATE 2: Here some other articles on the topic of long API symbols:

2 thoughts on “Mining for API trivia

  1. Pingback: Michael Tsai - Blog - Mining for API Trivia

  2. Pingback: In search of the longest public symbol in Apple APIs « [iOS developer:tips];

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.