Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

Next Page > Hide TOC

NSPersistentStore Class Reference

Inherits from
Framework
/System/Library/Frameworks/CoreData.framework
Availability
Available in Mac OS X v10.5 and later.
Declared in
NSPersistentStore.h
Companion guides

Overview

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

Core Data provides four store types —SQLite, Binary, XML, and In-Memory; these are described in Persistent Stores. Core Data also provides a subclass of NSPersistentStore, NSAtomicStore. The Binary and XML stores are examples of atomic stores that inherit functionality from NSAtomicStore.

Subclassing Notes

You should not subclass NSPersistentStore directly. Core Data currently only supports subclassing of NSAtomicStore.

The designated initializer is initWithPersistentStoreCoordinator:configurationName:URL:options:. When you implement the initializer, you must ensure you load metadata during initialization and set it using setMetadata:.

You must override these methods:

Tasks

Initializing a Persistent Store

Working with State Information

Managing Metadata

Setup and Teardown

Class Methods

metadataForPersistentStoreWithURL:error:

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

+ (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.

Availability
Declared In
NSPersistentStore.h

setMetadata:forPersistentStoreWithURL:error:

Sets the metadata for the store at a given URL.

+ (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

YES if the metadata was written correctly, otherwise NO.

Special Considerations

Subclasses must override this method to set metadata appropriately.

Availability
Declared In
NSPersistentStore.h

Instance Methods

configurationName

Returns the name of the managed object model configuration used to create the receiver.

- (NSString *)configurationName

Return Value

The name of the managed object model configuration used to create the receiver.

Availability
Declared In
NSPersistentStore.h

didAddToPersistentStoreCoordinator:

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

- (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.

Availability
Declared In
NSPersistentStore.h

identifier

Returns the unique identifier for the receiver.

- (NSString *)identifier

Return Value

The unique identifier for the receiver.

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.

Availability
See Also
Declared In
NSPersistentStore.h

initWithPersistentStoreCoordinator:configurationName:URL:options:

Returns a store initialized with the given arguments.

- (id)initWithPersistentStoreCoordinator:(NSPersistentStoreCoordinator *)root configurationName:(NSString *)name URL:(NSURL *)url options:(NSDictionary *)options

Parameters
coordinator

A persistent store coordinator.

configurationName

The name of the managed object model configuration to use.

url

The URL of the store to load.

options

A dictionary containing configuration options.

Return Value

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

Discussion

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

Special Considerations

This is the designated initializer for persistent stores.

Availability
See Also
Declared In
NSPersistentStore.h

isReadOnly

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

- (BOOL)isReadOnly

Return Value

YES if the receiver is read-only, otherwise NO.

Availability
Declared In
NSPersistentStore.h

metadata

Returns the metadata for the receiver.

- (NSDictionary *)metadata

Return Value

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

Special Considerations

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

Availability
Declared In
NSPersistentStore.h

options

Returns the options with which the receiver was created.

- (NSDictionary *)options

Return Value

The options with which the receiver was created.

Discussion

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

Availability
Declared In
NSPersistentStore.h

persistentStoreCoordinator

Returns the persistent store coordinator which loaded the receiver.

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator

Return Value

The persistent store coordinator which loaded the receiver.

Availability
Declared In
NSPersistentStore.h

setIdentifier:

Sets the unique identifier for the receiver.

- (void)setIdentifier:(NSString *)identifier

Parameters
identifier

The unique identifier for the receiver.

Availability
See Also
Declared In
NSPersistentStore.h

setMetadata:

Sets the metadata for the receiver.

- (void)setMetadata:(NSDictionary *)storeMetadata

Parameters
storeMetadata

The metadata for the receiver.

Availability
Declared In
NSPersistentStore.h

setReadOnly:

Sets whether the receiver is read-only.

- (void)setReadOnly:(BOOL)flag

Parameters
flag

YES if the receiver is read-only, otherwise NO.

Availability
Declared In
NSPersistentStore.h

setURL:

Sets the URL for the receiver.

- (void)setURL:(NSURL *)url

Parameters
url

The URL for the receiver.

Discussion

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

Availability
See Also
Declared In
NSPersistentStore.h

type

Returns the type string of the receiver.

- (NSString *)type

Return Value

The type string of the receiver.

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.

Availability
Declared In
NSPersistentStore.h

URL

Returns the URL for the receiver.

- (NSURL *)URL

Return Value

The URL for the receiver.

Availability
See Also
Declared In
NSPersistentStore.h

willRemoveFromPersistentStoreCoordinator:

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

- (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).

Availability
Declared In
NSPersistentStore.h

Next Page > Hide TOC


Last updated: 2007-07-22




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice