Class: NSPersistentStoreCoordinator
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)
-
+ metadataForPersistentStoreOfType:URL:error:
Returns a dictionary containing the metadata stored in the persistent store at a given URL.
-
+ registeredStoreTypes
Returns a dictionary of the registered store types.
-
+ registerStoreClass:forStoreType:
Registers a given NSPersistentStore subclass for a given store type string.
-
+ setMetadata:forPersistentStoreOfType:URL:error:
Sets the metadata for a given store.
Instance Method Summary (collapse)
-
- addPersistentStoreWithType:configuration:URL:options:error:
Adds a new persistent store of a specified type at a given location, and returns the new store.
-
- executeRequest:withContext:error:
Sends a request to all the persistent stores associated with the receiver.
-
- initWithManagedObjectModel:
Initializes the receiver with a managed object model.
-
- lock
Attempts to acquire a lock.
-
- managedObjectIDForURIRepresentation:
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.
-
- managedObjectModel
Returns the receiver’s managed object model.
-
- metadataForPersistentStore:
Returns a dictionary that contains the metadata currently stored or to-be-stored in a given persistent store.
-
- migratePersistentStore:toURL:options:withType:error:
Moves a persistent store to a new location, changing the storage type if necessary.
-
- persistentStoreForURL:
Returns the persistent store for the specified URL.
-
- persistentStores
Returns an array of persistent stores associated with the receiver.
-
- removePersistentStore:error:
Removes a given persistent store.
-
- setMetadata:forPersistentStore:
Sets the metadata stored in the persistent store during the next save operation executed on it to metadata.
-
- setURL:forPersistentStore:
Sets the URL for a given persistent store.
-
- tryLock
Attempts to acquire a lock.
-
- unlock
Relinquishes a previously acquired lock.
-
- URLForPersistentStore:
Returns the URL for a given persistent store.
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.
+ (Hash) registeredStoreTypes
Returns a dictionary of the registered store types.
+ (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.
+ (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.
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.
- (Object) executeRequest(request, withContext:context, error:error)
Sends a request to all the persistent stores associated with the receiver.
- (Object) initWithManagedObjectModel(model)
Initializes the receiver with a managed object 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.
- (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.
- (NSManagedObjectModel) managedObjectModel
Returns the receiver’s managed object model.
- (Hash) metadataForPersistentStore(store)
Returns a dictionary that contains the metadata currently stored or to-be-stored in a given persistent 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.
- (NSPersistentStore) persistentStoreForURL(URL)
Returns the persistent store for the specified URL.
- (Array) persistentStores
Returns an array of persistent stores associated with the receiver.
- (Boolean) removePersistentStore(store, error:error)
Removes a given persistent store.
- (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.
- (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.)
- (Boolean) tryLock
Attempts to acquire a lock. Returns immediately—contrast lock which blocks.
- (Object) unlock
Relinquishes a previously acquired lock.
- (NSURL) URLForPersistentStore(store)
Returns the URL for a given persistent store.