Document Package with iCloud
| Last Revision: | Version 1.0, 2012-12-10 "PackagedDocument" is a text editing application for opening, editing and saving packaged documents to iCloud using NSDocument and NSFileWrapper. |
| Build Requirements: | Xcode 4.4, OS X 10.8 |
| Runtime Requirements: | OS X 10.8, 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.
Querying for documents in iCloud: Included as part of this sample is a class called "CloudDocumentsController". It is used to perform Spotlight queries, using NSMetaDataQuery, to discoved files found in iCloud. You can use this class to quickly gain access to those available files.
© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-12-10)