问题
I want to save the content of a MOC
to a file myFile.ext
. Everything works well, my data is saved to the file BUT I have to auxiliary files in addition:
myFile.ext-wal
myFile.ext-shm
Are these files necessary for my purpose (saving the content of a MOC
to a file)? I would like to "ship" my data in only one file. Furthermore, when I get again my data, I only use the URL
of myFile.ext
.
If they are not necessary, is it possible to avoid their creation?
回答1:
As CL indicated they are necessary in WAL mode. To disable the journaling mode when creating your persistent store pass the flowing option.
NSDictionary *options = @{NSSQLitePragmasOption: @{@"journal_mode": @"DELETE"};
_coordinator = [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:options error:&storeError];
When you run your app again the -wal should disappear and the -shm can be deleted or ignored. All you data should be in the one sqlite file.
回答2:
These files are created (and are necessary) when the database is in WAL mode.
To disable WAL mode, open the database directly and execute PRAGMA journal_mode = DELETE.
来源:https://stackoverflow.com/questions/24291083/how-to-save-the-content-of-a-moc-to-a-file-with-no-wal-and-no-shm