Core Data 和 iOS 7:持久化存储的不同行为

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18870387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:19:29  来源:igfitidea点击:

Core Data and iOS 7: Different behavior of persistent store

iossqlitecore-dataios7uimanageddocument

提问by FrankZp

I'm preparing an update for a Core Data based app for fixes with iOS 7. I use Xcode 5 and iOS 7 SDK GM. However I realized a different behavior of the persistent store (which is a UIManagedDocument): Prior to iOS 7 builds there was only one file persistentStorein the documents folder (sometimes there was a second one persistentStore-journal).

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

In iOS 7 builds (clean installation) there are now three files for the persistent store:

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

  • persistentStore
  • persistentStore-waland
  • persistentStore-shm
  • persistentStore
  • persistentStore-wal
  • persistentStore-shm

Did Apple change the journal mode by default to WAL now? I wonder if there is an impact on my app (think of users how update from the last version)? Would it be best to disable WAL - and if so, how can I do this with iOS 7/UIManagedDocument?

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

回答by Andy Etheridge

Yes, Apple have changed the default journal mode to WAL for iOS7. You can specify the journal mode by adding the NSSQLitePragmasOption to the options when calling addPersistentStoreWithType:configuration:url:options:error. E.g. to set the previous default mode of DELETE:

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

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

In my experience WAL gives better performance, but also see this post:

根据我的经验,WAL 提供了更好的性能,但也可以查看这篇文章:

iOS CoreData - are there any disadvantages to enabling sqlite WAL / Write-Ahead Logging

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