【问题标题】:Has the Core Data database persistent storage location changedCore Data 数据库持久存储位置是否已更改
【发布时间】:2014-09-02 11:33:23
【问题描述】:

我遇到了许多其他人报告的持久性存储错误。但是,在我的情况下,这不是由于更改了数据库模型。我追了那只兔子几个小时。最后一篇文章引导我尝试删除数据库本身。我去了我的 URL 指向的目录

url=/Users/ccox/Library/Application Support/iPhone Simulator/7.1/Applications/8A231E05-B3A2-4E83-8C81-6B3989C262A5/Library/Documentation/DBEViewDocumentand

它不存在。 url=/Users/ccox/Library/Application Support/iPhone Simulator/7.1/Applications/8A231E05-B3A2-4E83-8C81-6B3989C262A5/Library/

在那里,但文档目录不在那里。

这是我用来获取 URL 的代码

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *documentsDirectory =[[fileManager URLsForDirectory:NSDocumentationDirectory inDomains:NSUserDomainMask] firstObject];
NSString *documentName = @"DBEViewDocument";
self.url = [documentsDirectory URLByAppendingPathComponent:documentName];
self.document = [[UIManagedDocument alloc] initWithFileURL:self.url];
NSLog(@"url=%@",[self.url path]);

NSLog 的输出就是上面的输出 URL。

是否有某个地方可以设置该文档目录的目标位置?显然,文档目录不是标准目录,因为它不是作为应用程序安装的一部分创建的。

我继续创建了文档目录,现在一切正常(至少到目前为止),但我不敢相信这是设计使然,每个人都必须这样做。

有什么想法吗? 谢谢 芯片

【问题讨论】:

    标签: ios objective-c url core-data persistent-storage


    【解决方案1】:

    您使用了错误的目录。 NSDocumentationDirectory 不是文档的标准位置,默认情况下不会创建。你想要NSDocumentDirectory,它默认创建的。

    【讨论】:

    • 谢谢,我要从讲座幻灯片中输入它们,而不是仅仅剪切和粘贴。有时我想我有点依赖自动完成功能。大声笑再次感谢
    猜你喜欢
    • 2012-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-07
    • 2012-09-10
    相关资源
    最近更新 更多