Document Package with iCloud
Version 1.1, 2013-06-13
Minor changes for clarity; updated to adopt current best practices for Objective-C.
(Full Revision History)
Xcode 4.6 or later, OS X 10.8 or later
OS X 10.8 or later, an iCloud account
"PackagedDocument" is a text editing application for opening, editing and saving packaged documents to iCloud using NSDocument and NSFileWrapper. This sample is ARC-enabled (Automatic Reference Counting).
File Format and NSFileWrapper: Choices you make in designing your document format can impact network transfer performance to and from iCloud for your app’s documents. The most important choice is to be sure to use a file package for your document format. If your document data format consists of multiple distinct pieces, use a file package for your document file format. A file package, which you access by way of an NSFileWrapper object, lets you store the elements of a document as individual files and folders that can be read and written separately—while still appearing to the user as a single file. The iCloud upload and download machinery makes use of this factoring of content within a file package; only changed elements are uploaded or downloaded.
Three distinctive components of the document format: This sample demonstrates the use of NSFileWrapper by writing three distinctive files: text, image and plist files. Each document window allows the user to add text and an image. The plist file is used as an internal metadata file used to hold misc information about that document, in particular the disclosure state of the image section of the window. It writes and reads the plist file using NSPropertyListSerialization.