Mac Developer Library

Developer

CoreData Framework Reference NSPersistentStore Class Reference

Options
Deployment Target:

On This Page
Language:

NSPersistentStore

This class is the abstract base class for all Core Data persistent stores. More...

Inheritance


Conforms To


Import Statement


import CoreData @import CoreData;

Availability


Available in OS X v10.5 and later.
  • Returns a store initialized with the given arguments.

    Declaration

    Swift

    init(persistentStoreCoordinator coordinator: NSPersistentStoreCoordinator, configurationName configurationName: String?, URL url: NSURL, options options: [NSObject : AnyObject]?)

    Objective-C

    - (instancetype)initWithPersistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator configurationName:(NSString *)configurationName URL:(NSURL *)url options:(NSDictionary *)options

    Parameters

    coordinator

    A persistent store coordinator.

    configurationName

    The name of the managed object model configuration to use. Pass nil if you do not want to specify a configuration.

    url

    The URL of the store to load.

    options

    A dictionary containing configuration options. See NSPersistentStoreCoordinator for a list of key names for options in this dictionary.

    Return Value

    A new store object, associated with coordinator, that represents a persistent store at url using the options in options and—if it is not nil—the managed object model configuration configurationName.

    Discussion

    You must ensure that you load metadata during initialization and set it using metadata.

    Special Considerations

    This is the designated initializer for persistent stores.

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.5 and later.

    See Also

    metadata

  • type type Property

    The type string of the receiver. (read-only)

    Declaration

    Swift

    var type: String { get }

    Objective-C

    @property(readonly, copy) NSString *type

    Discussion

    This string is used when specifying the type of store to add to a persistent store coordinator.

    Special Considerations

    Subclasses must override this method to provide a unique type.

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • The persistent store coordinator that loaded the receiver. (read-only)

    Declaration

    Swift

    weak var persistentStoreCoordinator: NSPersistentStoreCoordinator? { get }

    Objective-C

    @property(nonatomic, readonly, weak) NSPersistentStoreCoordinator *persistentStoreCoordinator

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • The name of the managed object model configuration used to create the receiver. (read-only)

    Declaration

    Swift

    var configurationName: String { get }

    Objective-C

    @property(readonly, copy) NSString *configurationName

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • options options Property

    The options the store was initialized with. (read-only)

    Declaration

    Swift

    var options: [NSObject : AnyObject]? { get }

    Objective-C

    @property(readonly, strong) NSDictionary *options

    Discussion

    See NSPersistentStoreCoordinator for a list of key names for options in this dictionary.

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • URL URL Property

    The URL for the receiver.

    Declaration

    Swift

    var URL: NSURL?

    Objective-C

    @property(strong) NSURL *URL

    Discussion

    To alter the location of a store, send the persistent store coordinator a setURL:forPersistentStore: message.

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • The unique identifier for the receiver.

    Declaration

    Swift

    var identifier: String!

    Objective-C

    @property(copy) NSString *identifier

    Discussion

    The identifier is used as part of the managed object IDs for each object in the store.

    Special Considerations

    NSPersistentStore provides a default implementation to provide a globally unique identifier for the store instance.

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.5 and later.

    See Also

    metadata

  • readOnly readOnly Property

    A Boolean value that indicates whether the receiver is read-only.

    Declaration

    Swift

    var readOnly: Bool

    Objective-C

    @property(getter=isReadOnly) BOOL readOnly

    Discussion

    YEStrue if the receiver is read-only, otherwise NOfalse.

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.10 and later.

  • Returns the metadata from the persistent store at the given URL.

    Declaration

    Swift

    class func metadataForPersistentStoreWithURL(_ url: NSURL, error error: NSErrorPointer) -> [NSObject : AnyObject]?

    Objective-C

    + (NSDictionary *)metadataForPersistentStoreWithURL:(NSURL *)url error:(NSError **)error

    Parameters

    url

    The location of the store.

    error

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

    Return Value

    The metadata from the persistent store at url. Returns nil if there is an error.

    Special Considerations

    Subclasses must override this method.

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • Sets the metadata for the store at a given URL.

    Declaration

    Swift

    class func setMetadata(_ metadata: [NSObject : AnyObject]?, forPersistentStoreWithURL url: NSURL, error error: NSErrorPointer) -> Bool

    Objective-C

    + (BOOL)setMetadata:(NSDictionary *)metadata forPersistentStoreWithURL:(NSURL *)url error:(NSError **)error

    Parameters

    metadata

    The metadata for the store at url.

    url

    The location of the store.

    error

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

    Return Value

    YEStrue if the metadata was written correctly, otherwise NOfalse.

    Special Considerations

    Subclasses must override this method to set metadata appropriately.

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • metadata metadata Property

    The metadata for the receiver.

    Declaration

    Swift

    var metadata: [NSObject : AnyObject]!

    Objective-C

    @property(nonatomic, strong) NSDictionary *metadata

    Discussion

    The dictionary must include the store type (NSStoreTypeKey) and UUID (NSStoreUUIDKey).

    Special Considerations

    Subclasses must override this property to provide storage and persistence for the store metadata.

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • Instructs the receiver to load its metadata.

    Declaration

    Swift

    func loadMetadata(_ error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)loadMetadata:(NSError **)error

    Parameters

    error

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

    Return Value

    YEStrue if the metadata was loaded correctly, otherwise NOfalse.

    Special Considerations

    There is no way to return an error if the store is invalid.

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.6 and later.

  • Invoked after the receiver has been added to the persistent store coordinator.

    Declaration

    Swift

    func didAddToPersistentStoreCoordinator(_ coordinator: NSPersistentStoreCoordinator)

    Objective-C

    - (void)didAddToPersistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator

    Parameters

    coordinator

    The persistent store coordinator to which the receiver was added.

    Discussion

    The default implementation does nothing. You can override this method in a subclass in order to perform any kind of setup necessary before the load method is invoked.

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • Invoked before the receiver is removed from the persistent store coordinator.

    Declaration

    Swift

    func willRemoveFromPersistentStoreCoordinator(_ coordinator: NSPersistentStoreCoordinator)

    Objective-C

    - (void)willRemoveFromPersistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator

    Parameters

    coordinator

    The persistent store coordinator from which the receiver was removed.

    Discussion

    The default implementation does nothing. You can override this method in a subclass in order to perform any clean-up before the store is removed from the coordinator (and deallocated).

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.5 and later.

  • Returns the NSMigrationManager class for this store class.

    Declaration

    Swift

    class func migrationManagerClass() -> AnyClass

    Objective-C

    + (Class)migrationManagerClass

    Return Value

    The NSMigrationManager class for this store class

    Discussion

    In a subclass of NSPersistentStore, you can override this to provide a custom migration manager subclass (for example, to take advantage of store-specific functionality to improve migration performance).

    Import Statement

    import CoreData

    Availability

    Available in OS X v10.6 and later.