Class: NSPersistentStoreCoordinator

Inherits:
NSObject show all

Overview

Instances of NSPersistentStoreCoordinator associate persistent stores (by type) with a model (or more accurately, a configuration of a model) and serve to mediate between the persistent store or stores and the managed object context or contexts. Instances of NSManagedObjectContext use a coordinator to save object graphs to persistent storage and to retrieve model information. A context without a coordinator is not fully functional as it cannot access a model except through a coordinator. The coordinator is designed to present a façade to the managed object contexts such that a group of persistent stores appears as an aggregate store. A managed object context can then create an object graph based on the union of all the data stores the coordinator covers.

Class Method Summary (collapse)

Instance Method Summary (collapse)

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

Class Method Details

+ (Hash) metadataForPersistentStoreOfType(storeType, URL:url, error:error)

Returns a dictionary containing the metadata stored in the persistent store at a given URL. You can use this method to retrieve the metadata from a store without the overhead of creating a Core Data stack.

Parameters:

  • storeType (String)

    The type of the store at url. If this value is nil, Core Data determines which store class should be used to get or set the store file's metadata by inspecting the file contents.

  • url (NSURL)

    The location of a persistent store.

  • error (Pointer)

    If no store is found at url or if there is a problem accessing its contents, upon return contains an NSError object that describes the problem.

Returns:

  • (Hash)

    A dictionary containing the metadata stored in the persistent store at url, or nil if the store cannot be opened or if there is a problem accessing its contents.The keys guaranteed to be in this dictionary are NSStoreTypeKey and NSStoreUUIDKey.

+ (Hash) registeredStoreTypes

Returns a dictionary of the registered store types.

Returns:

  • (Hash)

    A dictionary of the registered store types—the keys are the store type strings, and the values are the NSPersistentStore subclasses.

+ (Object) registerStoreClass(storeClass, forStoreType:storeType)

Registers a given NSPersistentStore subclass for a given store type string. You must invoke this method before a custom subclass of NSPersistentStore can be loaded into a persistent store coordinator.You can pass nil for storeClass to unregister the store type.

Parameters:

  • storeClass (Class)

    The NSPersistentStore subclass to use for the store of type storeType.

  • storeType (String)

    A unique string that identifies a store type.

Returns:

+ (Boolean) setMetadata(metadata, forPersistentStoreOfType:storeType, URL:url, error:error)

Sets the metadata for a given store. You can use this method to set the metadata for a store without the overhead of creating a Core Data stack.

Parameters:

  • metadata (Hash)

    A dictionary containing metadata for the store.

  • storeType (String)

    The type of the store at url. If this value is nil, Core Data will determine which store class should be used to get or set the store file's metadata by inspecting the file contents.

  • url (NSURL)

    The location of a persistent store.

  • error (Pointer)

    If no store is found at url or if there is a problem setting its metadata, upon return contains an NSError object that describes the problem.

Returns:

  • (Boolean)

    YES if the metadata was set correctly, otherwise NO.

Instance Method Details

- (NSPersistentStore) addPersistentStoreWithType(storeType, configuration:configuration, URL:storeURL, options:options, error:error)

Adds a new persistent store of a specified type at a given location, and returns the new store.

Parameters:

  • storeType (String)

    A string constant (such as NSSQLiteStoreType) that specifies the store type—see “Store Types” for possible values.

  • configuration (String)

    The name of a configuration in the receiver’s managed object model that will be used by the new store. The configuration can be nil, in which case no other configurations are allowed.

  • storeURL (NSURL)

    The file location of the persistent store.

  • options (Hash)

    A dictionary containing key-value pairs that specify whether the store should be read-only, and whether (for an XML store) the XML file should be validated against the DTD before it is read. For key definitions, see “Store Options” and “Migration Options”. This value may be nil.

  • error (Pointer)

    If a new store cannot be created, upon return contains an instance of NSError that describes the problem

Returns:

- (Object) executeRequest(request, withContext:context, error:error)

Sends a request to all the persistent stores associated with the receiver.

Parameters:

Returns:

  • (Object)

    An array containing managed objects, managed object IDs, or dictionaries as appropriate for a fetch request; an empty array if request is a save request, or nil if an error occurred.User defined requests return arrays of arrays, where a nested array is the result returned from a single store.

- (Object) initWithManagedObjectModel(model)

Initializes the receiver with a managed object model.

Parameters:

Returns:

  • (Object)

    The receiver, initialized with model.

- (Object) lock

Attempts to acquire a lock. This method blocks a thread’€™s execution until the lock can be acquired. An application protects a critical section of code by requiring a thread to acquire a lock before executing the code. Once the critical section is past, the thread relinquishes the lock by invoking unlock.

Returns:

- (NSManagedObjectID) managedObjectIDForURIRepresentation(URL)

Returns an object ID for the specified URI representation of an object ID if a matching store is available, or nil if a matching store cannot be found. The URI representation contains a UUID of the store the ID is coming from, and the coordinator can match it against the stores added to it.

Parameters:

  • URL (NSURL)

    An URL object containing a URI that specify a managed object.

Returns:

- (NSManagedObjectModel) managedObjectModel

Returns the receiver’s managed object model.

Returns:

- (Hash) metadataForPersistentStore(store)

Returns a dictionary that contains the metadata currently stored or to-be-stored in a given persistent store.

Parameters:

Returns:

  • (Hash)

    A dictionary that contains the metadata currently stored or to-be-stored in store.

- (NSPersistentStore) migratePersistentStore(store, toURL:URL, options:options, withType:storeType, error:error)

Moves a persistent store to a new location, changing the storage type if necessary. This method is typically used for “Save As”€ operations. Performance may vary depending on the type of old and new store. For more details of the action of this method, see “Persistent Store Features” in Core Data Programming Guide.Important:  After invocation of this method, the specified store is removed from the coordinator thus store is no longer a useful reference.

Parameters:

  • store (NSPersistentStore)

    A persistent store.

  • URL (NSURL)

    An URL object that specifies the location for the new store.

  • options (Hash)

    A dictionary containing key-value pairs that specify whether the store should be read-only, and whether (for an XML store) the XML file should be validated against the DTD before it is read. For key definitions, see “Store Options.”

  • storeType (String)

    A string constant (such as NSSQLiteStoreType) that specifies the type of the new store—see “Store Types.”

  • error (Pointer)

    If an error occurs, upon return contains an instance of NSError that describes the problem.

Returns:

  • (NSPersistentStore)

    If the migration is successful, the new store, otherwise nil.

- (NSPersistentStore) persistentStoreForURL(URL)

Returns the persistent store for the specified URL.

Parameters:

  • URL (NSURL)

    An URL object that specifies the location of a persistent store.

Returns:

- (Array) persistentStores

Returns an array of persistent stores associated with the receiver.

Returns:

  • (Array)

    An array persistent stores associated with the receiver.

- (Boolean) removePersistentStore(store, error:error)

Removes a given persistent store.

Parameters:

  • store (NSPersistentStore)

    A persistent store.

  • error (Pointer)

    If an error occurs, upon return contains an instance of NSError that describes the problem.

Returns:

  • (Boolean)

    YES if the store is removed, otherwise NO.

- (Object) setMetadata(metadata, forPersistentStore:store)

Sets the metadata stored in the persistent store during the next save operation executed on it to metadata. The store type and UUID (NSStoreTypeKey and NSStoreUUIDKey) are always added automatically, however NSStoreUUIDKey is only added if it is not set manually as part of the dictionary argument.Important:  Setting the metadata for a store does not change the information on disk until the store is actually saved.

Parameters:

  • metadata (Hash)

    A dictionary containing metadata for the store.

  • store (NSPersistentStore)

    A persistent store.

Returns:

- (Boolean) setURL(url, forPersistentStore:store)

Sets the URL for a given persistent store. For atomic stores, this method alters the location to which the next save operation will write the file; for non-atomic stores, invoking this method will relinquish the existing connection and create a new one at the specified URL. (For non-atomic stores, a store must already exist at the destination URL; a new store will not be created.)

Parameters:

  • url (NSURL)

    The new location for store.

  • store (NSPersistentStore)

    A persistent store associated with the receiver.

Returns:

  • (Boolean)

    YES if the store was relocated, otherwise NO.

- (Boolean) tryLock

Attempts to acquire a lock. Returns immediately—contrast lock which blocks.

Returns:

  • (Boolean)

    YES if successful, otherwise NO.

- (Object) unlock

Relinquishes a previously acquired lock.

Returns:

- (NSURL) URLForPersistentStore(store)

Returns the URL for a given persistent store.

Parameters:

Returns:

  • (NSURL)

    The URL for store.