Class: UIManagedDocument

Inherits:
UIDocument show all

Overview

UIManagedDocument is a concrete subclass of UIDocument that integrates with Core Data. When you initialize a managed document, you specify the URL for the document location. The document object then creates a Core Data stack to use to access the document’s persistent store using managed object model from the application’s main bundle.

Instance Attribute Summary (collapse)

Attributes inherited from UIDocument

#documentState, #fileModificationDate, #fileType, #fileURL, #localizedName, #undoManager

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from UIDocument

#autosaveWithCompletionHandler:, #changeCountTokenForSaveOperation:, #closeWithCompletionHandler:, #contentsForType:error:, #disableEditing, #enableEditing, #fileAttributesToWriteToURL:forSaveOperation:error:, #fileNameExtensionForType:saveOperation:, #finishedHandlingError:recovered:, #handleError:userInteractionPermitted:, #hasUnsavedChanges, #initWithFileURL:, #loadFromContents:ofType:error:, #openWithCompletionHandler:, #performAsynchronousFileAccessUsingBlock:, #readFromURL:error:, #revertToContentsOfURL:completionHandler:, #saveToURL:forSaveOperation:completionHandler:, #savingFileType, #updateChangeCount:, #updateChangeCountWithToken:forSaveOperation:, #userInteractionNoLongerPermittedForError:, #writeContents:andAttributes:safelyToURL:forSaveOperation:error:, #writeContents:toURL:forSaveOperation:originalContentsURL:error:

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Instance Attribute Details

- (NSManagedObjectContext) managedObjectContext (readonly)

The document’s managed object context. (read-only) The document automatically creates a managed object context using its persistent store coordinator.

- (NSManagedObjectModel) managedObjectModel (readonly)

The document’s managed object model. (read-only) Persistent documents always have a managed object model. The default model is the union of all models in the main bundle. You can specify a configuration to use with modelConfiguration. You can subclass UIManagedDocument to override this method if you need custom behavior.

- (String) modelConfiguration

A model configuration name to be passed when configuring the persistent store. By default, this value is nil.

Returns:

- (Hash) persistentStoreOptions

Options used when creating the document’s persistent store. By default, this value is nil.To support automatic migration, you might pass a dictionary like that shown in the following example.

Returns:

Class Method Details

+ (String) persistentStoreName

Returns the name for the persistent store file inside the document’s file package. This path component is appended to the document URL provided by UIDocument. The default name is persistentStore.

Returns:

  • (String)

    The name for the persistent store file inside the document’s file package.

Instance Method Details

- (Object) additionalContentForURL(absoluteURL, error:error)

Handles writing non-Core Data content to the additional content directory in the document’s file package. You override this method to perform to manage non-Core Data content to be stored in the additional content directory in the document’s file package.If you implement this method, it is invoked automatically by contentsForType:error:. The returned object is passed to writeAdditionalContent:toURL:originalContentsURL:error:.There is no need to invoke super’s implementation.

Parameters:

  • absoluteURL (NSURL)

    The URL for the additional content directory in the document’s file package.

  • error (Pointer)

    Upon return, if a problem occurs, contains an error object that describes the problem.

Returns:

  • (Object)

    An object that contains the additional content for the document at absoluteURL, or nil if there is a problem.

- (Boolean) configurePersistentStoreCoordinatorForURL(storeURL, ofType:fileType, modelConfiguration:configuration, storeOptions:storeOptions, error:error)

Creates or loads the document’s persistent store. You can override this method if you want customize the creation or loading of the document’s persistent store. For example, you can perform post-migration clean-up—if your application needs to migrate store data to use a new version of the managed object model, you can override this method to make additional modifications to the store after migration.

Parameters:

  • storeURL (NSURL)

    The URL for the persistent store.

  • fileType (String)

    The document’s file type.

  • configuration (String)

    The managed object model configuration to use.

  • storeOptions (Hash)

    The options used to configure the persistent store coordinator.

  • error (Pointer)

    Upon return, if a problem occurs, contains an error object that describes the problem.

Returns:

  • (Boolean)

    YES if configuration is successful, otherwise NO.

- (String) persistentStoreTypeForFileType(fileType)

Returns the Core Data store type for a given document file type. Override this method to specify a persistent store type for a given document type.The default returns NSSQLiteStoreType.

Parameters:

  • fileType (String)

    The document file type.

Returns:

  • (String)

    The persistent store type for fileType.

- (Boolean) readAdditionalContentFromURL(absoluteURL, error:error)

Handles reading non-Core Data content in the additional content directory in the document’s file package. You override this method to read non-Core Data content from the additional content directory in the document’s file package.If you implement this method, it is invoked automatically by readFromURL:error:.There is no need to invoke super’s implementation.

Parameters:

  • absoluteURL (NSURL)

    The URL for the additional content directory in the document’s file package.

  • error (Pointer)

    Upon return, if a problem occurs, contains an error object that describes the problem.

Returns:

  • (Boolean)

    YES if the read operation is successful, otherwise NO.

- (Boolean) writeAdditionalContent(content, toURL:absoluteURL, originalContentsURL:absoluteOriginalContentsURL, error:error)

Handles writing non-Core Data content to the document’s file package. You override this method to perform to write non-Core Data content in the additional content directory in the document’s file package. There are several issues to consider:You should typically implement this method only if you have also implemented additionalContentForURL:error:.Because this method is executed asynchronously, it is possible that the document’s state may be different from that at which the save operation was initiated. If you need to capture the document state at save time, you should do so in additionalContentForURL:error:. If you implement this method, it is invoked automatically by writeContents:andAttributes:safelyToURL:forSaveOperation:error:.There is no need to invoke super’s implementation.

Parameters:

  • content (Object)

    An object that represents the additional content for the document.This is the object returned from additionalContentForURL:error:.

  • absoluteURL (NSURL)

    The URL to which to write the additional content.

  • absoluteOriginalContentsURL (NSURL)

    The current URL of the document that is being saved.

  • error (Pointer)

    Upon return, if a problem occurs, contains an error object that describes the problem.

Returns:

  • (Boolean)

    YES if the write operation is successful, otherwise NO.