OS X 10.6 Snow Leopard introduced a wealth of new APIs on NSURL. In particular, a set of methods for dealing with bookmark data.
A great many developers, Karelia included, have a need to keep references to files that might be moved to a new location by the user. Prior to 10.6, the best way to accomplish this was by using the old Carbon Alias Manager to create alias records, and then store the record’s data.
Snowy supersedes those APIs with native Cocoa methods on NSURL. They’re pretty straightforward and match up pretty closely to the old alias record concepts:
- The bookmarkData… methods take a URL or alias file and create bookmark data from it. You can then persist that data as your app sees fit
- +URLByResolvingBookmarkData:… performs the reverse, locating the best match for the file on disk (there’s an equivalent -init method too)
Do you have existing alias record data that needs bringing into the new world? (This includes the popular NDAlias and BDAlias wrappers). You might imagine “bookmark data” is just Cocoa’s terminology for a wrapper around the old APIs, but that’s not the case.
Bookmarks use their own custom format (I assume Apple has good reason for this) that’s incompatible with the alias manager. Conversion is one-way and you have to drop down to CoreFoundation: CFURLCreateBookmarkDataFromAliasRecord.
Now is the time to look at adopting these APIs, since OS X 10.7.3 introduces an extension to the bookmark format: security-scoped bookmarks. NSURL has new options and methods to accommodate this. There’s a good chance your app will want to adopt these for when/if sandboxing rules come into effect for the app store.