Core Data and iOS 7: Different behavior of persistent store

FrankZp picture FrankZp · Sep 18, 2013 · Viewed 22.5k times · Source

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 persistentStore in the documents folder (sometimes there was a second one persistentStore-journal).

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

  • persistentStore
  • persistentStore-wal and
  • 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?

Answer

Andy Etheridge picture Andy Etheridge · Sep 18, 2013

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:

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

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

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