Databases Reference
In-Depth Information
Once the choice between using a UIManagedDocument or a standard Core Data
Stack has been made, the behavior of iCloud is the same. Therefore, we are
going to start by examining UIManagedDocument and then look at wiring iCloud
into a standard stack. Once we are past those differences, we will take a
deeper dive into the other details of using iCloud.
6.1
Introducing the UIManagedDocument
In the release of iCloud, Apple introduced a new API called UIDocument . UIDocument
is designed to be an abstract parent class that makes it easy to integrate
applications with iCloud. One of the Core Data API changes for iOS 6.0 is
UIManagedDocument , a subclass of UIDocument .
Fundamentally, the biggest advantage of using UIManagedDocument is the ability
to abstract away the saving and state of your Core Data stack. With UIManaged-
Document , saving is handled automatically and generally occurs asynchronously.
You can request saves to occur more frequently than the autosave handles,
but in general you shouldn't need to do that. In addition to managing the
saving of the Core Data stack, UIManagedDocument has added features that allow
you to store files outside of the persistent store that will also be pushed to
iCloud.
UIManagedDocument is meant to be used in applications that have a document
design. Pages, Numbers, Omnigraffle, and so on, are great examples of iOS
applications that manage a form of document. Having said that, however,
there is nothing stopping you from using a UIManagedDocument as your single
Core Data stack enclosure. It is not specifically designed for a single stack
design, but it will work. It is even appealing in some ways, since it abstracts
out the creation of the stack.
iCloud/PPRecipes/PPRAppDelegate.m
dispatch_queue_t queue;
queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *storeURL = nil;
storeURL = [[fileManager URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
storeURL = [storeURL URLByAppendingPathComponent:@ "PPRecipes" ];
NSURL *cloudURL = [fileManager URLForUbiquityContainerIdentifier:nil];
The first step in constructing a UIManagedDocument is to resolve the file URL
where we will store the document and determine what the file URL is going
to be for iCloud. The first step, where we are saving the data to, is virtually
 
 
 
Search WWH ::




Custom Search