I’d like to store some additional information along with a document, but I can’t use bundles or packages, and I cannot store it inside the document itself.
The application is a text editor, and I’d like it to store code folding and bookmark locations with the document, but obviously this cannot be embedded into the code directly, and I don’t want to alter the code with ugly comments.
Can I use NSDocument to store information in the resource fork of a document? If so, how can I do this? Should I directly write to <filename>/..namedfork/rsrc or is there an API available?
First, don’t use the resource fork. It’s virtually deprecated. Instead, use extended attributes. They can be set programmatically at the BSD level via
setxattrandgetxattr. Extended attributes are used in many places… for example, in the latest OS X, the resource fork itself is implemented as a special type of extended attributes.For example, the Cocoa text system automatically adds an extended attribute to a file to specify the encoding.
I thought
NSFileManagerandNSFileWrappersupported extended attributes since Snow Leopard, but I can’t find any documentation :p You can always use the BSD level functions, though.