Сохраните ссылку на файл после того, как это переместится в цель-c?

Я просто отсылаю Вас к Вопрос 5.3 из C-FAQ. Это отвечает на этот точный вопрос.

14
задан Austin 23 September 2009 в 20:41
поделиться

1 ответ

In OS X 10.6 (Snow Leopard), an NSURL can be converted to a file reference URL (using -[NSURL fileReferenceURL]) which references a file across moves while your application is running. If you want to persist this file reference, use +[NSURL writeBookmarkData:toURL:options:error:] passing the bookmark data generated with -[NSURL bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error]. The bookmark can be resolved later with +[NSURL URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:] passing the bookmark data returned from +[NSURL bookmarkDataWithContentsOfURL:error:].

Prior to OS X 10.6, the same functionality (minus some network aware niceties) is available via the AliasManager, a Carbon-era interface to the OS X file alias system. There are a couple of Objective-C wrappers on top of the Alias Manager that make using it from Cocoa much nicer. My favorite is Wolf Rentzsch's additions to Chris Hanson's BDAlias (available on github).

18
ответ дан 1 December 2019 в 10:04
поделиться