Error retrieving store metadata using the class method NSPersistentStore

Im exploring user migration of the main database, for which I need to run a test in an existing repository to find out if it is compatible with the currently loaded mom. And for this I need to get metadata from the repository.

So, I do this in the AppDelegate class:

NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *applicationSupportDirectory = [self applicationSupportDirectory]; NSURL *url = [NSURL fileURLWithPath: [applicationSupportDirectory stringByAppendingPathComponent: @"sharedPersistMainStore.sqlite"]]; NSDictionary *storeMetadata = [NSPersistentStore metadataForPersistentStoreWithURL:url error:&error]; 

But I get this error:

metadataForPersistentStoreWithURL: error: cannot be sent to an abstract object of the NSPersistentStore class: create a specific instance!

Theyre telling me to use this as an instance method. But the API definitely lists it as a class method.

Still strange, calling this (deprecated) method works as expected:

 NSDictionary *storeMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreWithURL:url error:&error]; 

Except for the warning that this is an obsolete method.

Any ideas on what's going on?

+4
source share
2 answers

To use this method, you need a subclass of NSAtomicStore

+1
source

NSPersistentStore - an abstract class, you call the method of unfulfilled classes. To get metadata for a repository, you must first register it with the persistent repository coordinator, then request the repository coordinator using NSPersistentStoreCoodinator 's + metadataForPersistentStoreWithURL:error , or:

 NSPersistentStore *store = [coordinator persistentStoreForURL:url]; NSDictionary *storeMetadata = [[store metadata] copy]; 
+1
source

All Articles