persistentstorecoordinator sqlite error code:522 'not an error'

By changing the journaling mode you only avoid the problem but you do not fix it. The new journaling mode gives your app some benefits like speed.

The real problem is you delete only 1 file instead of all 3 that are used in that mode. There's not only your coredatadb.sqlite but also an coredatadb.sqlite-shm and and coredatadb.sqlite-wal file. Something about schema and write-ahead or so, check the WWDC 2013 videos on Core Data for details. [Update: It starts at minute 40 in the https://developer.apple.com/videos/play/wwdc2013/207/ video]

To fix your problem, you should delete all files in the Documents directory that begin with "coredatadb.sqlite" and everything is free and easy again ;-)

Update for iOS 9: It is easier and safer now to use destroyPersistentStoreAtURL or replacePersistentStoreAtURL. See WWDC 2015 session 220_hd_whats_new_in_core_data.


So it looks like the following solved my specific issue, although some people will advise against changing the journaling mode on your sqlite database:

// Change journal mode from WAL to MEMORY
NSDictionary *pragmaOptions = [NSDictionary dictionaryWithObject:@"MEMORY" forKey:@"journal_mode"];

 NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
 [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
 [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, 
 pragmaOptions, NSSQLitePragmasOption, nil];