Registering a Custom Store Type
To use a custom store type in an application, you must register the store type with the NSPersistentStoreCoordinator
class using registerStoreClass:forStoreType:
. The type name must be a unique string.
Typically you define the store type as a string constant:
// in MyAtomicStore.h |
extern NSString *MY_ATOMIC_STORE_TYPE; |
// in MyAtomicStore.m |
NSString *MY_ATOMIC_STORE_TYPE = @"MyAtomicStore"; |
You should ensure that a type is registered before you try to add a store of that type to a persistent store coordinator. For example, in an application delegate in OS X you might register in applicationWillFinishLaunching:
.
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification |
{ |
[NSPersistentStoreCoordinator registerStoreClass:[MyAtomicStore class] |
forStoreType:MY_ATOMIC_STORE_TYPE]; |
} |
In a document-based application, the type is the identifier NSPersistentDocument
uses to associate a persistent store type with a document type (see persistentStoreTypeForFileType:
).
Copyright © 2011 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2011-10-12