One of our projects currently in development is, at its heart, a rich text editor. I was
considering the issue of import/export of standard text file-formats (primarily RTF/D),
and it occurred to me that a far better solution was available.
Since RTFD is natively supported by Cocoa, it makes sense to leverage that support
as much as possible. Accordingly, our primary document file-format will be a package which
simply contains an RTFD file, holding the text and conventional attachments. Also in the package
will be a property list containing other persistent data, with an integer element for versioning.
There are several advantages to this approach:
- Archiving/unarchiving are considerably simplified, and made more modular.
- Versioning of file-formats is much easier to deal with, and backward- as well as forward-compatibility
is readily implemented. You're just asking an NSDictionary if it has an object for a given key, after all.
- Within a seemingly-proprietary file, you find only standard, documented formats - not the
undocumented, cryptic binary format natively produced by NSArchiver etc.
- Thus, other applications can readily make use of the files, taking either just the raw
RTF/D content or choosing which of the additional attributes to respect.
- Similarly, other apps can write/export to your format easily, if required.
- Users can always access the data in your app's files, even if they don't have your app handy.
Every OS X installation includes TextEdit.
- Import/export of RTF/D become trivial to implement.
- Files are much more easily verified, and corruption diagnosed.
I can only assume that many apps actually already take this approach inside their file packages.