我正在探索Core数据自定义迁移,为此我需要在现有存储上运行一个测试,看看它是否与当前加载的mom兼容。要做到这一点,我需要从商店获取元数据。
所以我在AppDelegate类中这样做:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *applicationSupportDirectory = [self applicationSupportDirectory];
NSURL *url = [NSURL fileURLWithPath: [applicationSupportDirectory stringByAppendingPathComponent: @"sharedPersistMainStore.sqlite"]];
NSDictionary *storeMetadata = [NSPersistentStore metadataForPersistentStoreWithURL:url error:&error];但我知道这个错误:
metadataForPersistentStoreWithURL:error:无法发送到类NSPersistentStore的抽象对象:创建一个具体实例!
听起来他们要我用这个作为一个实例方法。但是API肯定将其作为一个类方法列出。
更奇怪的是,调用此(已弃用的)方法如预期的那样工作:
NSDictionary *storeMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreWithURL:url error:&error];除了警告它是一个不推荐的方法之外。
有什么好主意吗?
发布于 2010-11-06 20:59:18
您需要对NSAtomicStore进行子类以使用该方法。
发布于 2015-01-17 23:13:52
NSPersistentStore是一个抽象类,您正在调用一个未实现的类方法。要获取存储的元数据,必须首先向持久存储协调器注册元数据,然后使用NSPersistentStoreCoodinator的+ metadataForPersistentStoreWithURL:error或:
NSPersistentStore *store = [coordinator persistentStoreForURL:url];
NSDictionary *storeMetadata = [[store metadata] copy];https://stackoverflow.com/questions/4115122
复制相似问题