Database Reference
In-Depth Information
Support for conflict resolution.
Safe saving of document data by writing a temporary file first and then
overwriting the old document.
Automatic saving of document data at opportune moments by the system.
What does this mean to you though? This means that you have to write less of the management
code and can actually concentrate on your app and your document model. You won't have to waste
any time and effort on writing or optimizing these tasks as Apple has already done that for you.
To subclass UIDocument you must implement two methods. Those are contentsForType:error :
and loadFromContents:ofType:error :. These two methods handle the reading and writing of your
document.
We will be using UIDocument to save a document package because we will be handling images and
text with the use of NSFileWrapper . You could however save a data blob if your file was a singular
piece of data, but overall it is not recommended. Packages are much more efficient for both the local
file system and iCloud.
In this section we will create our object models, which will conform to the NSCoding protocol, as well
as our UIDocument subclass. Once we have those created we will then go back to our test app and
begin modifying our Collection View Controller, Collection View Cell, and Detail View Controller to
handle our UIDocument . Let's get started.
Our Document Model
We start out by creating a data model for our documents metadata. Splitting up our document
model in such a way allows us to be more efficient when viewing the documents we have before
we decide to view one of them. Metadata is lightweight as compared to the actual data inside our
document so it is passed around a lot quicker and uses less memory.
Let's create a new Objective-C class that is a subclass of NSObject . We will call this class CTMetadata .
Now open the CTMetadata.h file. The first thing we want to do is subscribe to the NSCoding protocol.
The NSCoding protocol declares the two methods that a class must implement so that instances of
that class can be encoded and decoded. This capability provides the basis for archiving (where objects
and other structures are stored on disk) and distribution (where objects are copied to different address
spaces). Our interface line should now look like this:
@interface CTMetadata : NSObject <NSCoding>
We also need to add two public properties. One will be for our thumbnail, which is displayed
in the CollectionViewCell and the other is our display name, which is also displayed in the
CollectionViewCell.
@property (strong) UIImage *thumbnail;
@property (strong) NSString *displayName;
Moving over to the CTMetadata.m file we will create three local constants using defines. These should
be just after the import statement, but before the @implementation line.
 
Search WWH ::




Custom Search