68

我正在为基于 Core Data 的应用程序准备更新,以修复 iOS 7。我使用 Xcode 5 和 iOS 7 SDK GM。但是我意识到持久存储(即 a UIManagedDocument)的不同行为:在 iOS 7 构建之前,documents 文件夹中只有一个文件persistentStore(有时还有第二个文件persistentStore-journal)。

在 iOS 7 构建(全新安装)中,持久存储现在有三个文件:

  • persistentStore
  • persistentStore-wal
  • persistentStore-shm

Apple 现在默认将日志模式更改为 WAL 了吗?我想知道是否对我的应用程序有影响(想想用户如何从上一个版本更新)?最好禁用 WAL - 如果是这样,我该如何使用 iOS 7/ 执行此操作UIManagedDocument

4

1 回答 1

98

是的,Apple 已将 iOS7 的默认日记模式更改为 WAL。您可以通过在调用 addPersistentStoreWithType:configuration:url:options:error 时将 NSSQLitePragmasOption 添加到选项来指定日志模式。例如设置以前的默认删除模式:

NSDictionary *options = @{ NSSQLitePragmasOption : @{@"journal_mode" : @"DELETE"} };

根据我的经验,WAL 提供了更好的性能,但也请参阅这篇文章:

iOS CoreData - 启用 sqlite WAL / Write-Ahead Logging 有什么缺点吗

于 2013-09-18T11:14:07.343 回答