gpt4 book ai didi

macos - 在 NSPersistentDocument 上启用核心数据的自动轻量级迁移

转载 作者:行者123 更新时间:2023-12-04 23:30:18 24 4
gpt4 key购买 nike

ALM 很棒。但是我无法让它在使用带有 NSDocument 的 Core Data 的项目上工作。似乎默认情况下禁用了 ALM。

美好的。对于任何普通项目,您需要在此行的字典中添加两个适当的选项:

if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error])

...但是当将 CD 与 NSD 一起使用时,该行不存在(NSPersistentDocument 隐藏了详细信息,我看不到您如何修改它们)。

以下方法似乎提供了希望:
configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error:

...邮件列表上的一些人(从 4 年前开始)报告成功覆盖该方法,更改选项字典,然后在“ super ”上重新调用它。可悲的是,这对我不起作用。如果您有类似的问题,我建议您先尝试 - 如果它仍然不起作用,请回到这里:)

最佳答案

从头开始制作一个新的 Cored-Data-with-NSDocument 项目,尝试了最初行不通的方法,这次效果很好:

-(BOOL)configurePersistentStoreCoordinatorForURL:(NSURL *)url ofType:(NSString *)fileType modelConfiguration:(NSString *)configuration storeOptions:(NSDictionary *)storeOptions error:(NSError **)error
{
NSMutableDictionary *newOptions = [NSMutableDictionary dictionaryWithDictionary:storeOptions];
[newOptions setValue:@"YES" forKey:NSMigratePersistentStoresAutomaticallyOption];
[newOptions setValue:@"TRUE" forKey:NSInferMappingModelAutomaticallyOption];

return [super configurePersistentStoreCoordinatorForURL:url ofType:fileType modelConfiguration:configuration storeOptions:newOptions error:error];
}

关于macos - 在 NSPersistentDocument 上启用核心数据的自动轻量级迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6012177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com