úterý 30. září 2014

Core data - metadataForPersistentStoreOfType fails after iPhone restart.

In our application, we often need to do core data migration when we create a new release. To do this we first need to get the metadata from our app’s persistent store,  so that it can be migrated. We use the following line of code for this:

[NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType URL:self.storeURL error:&error];

However, we noticed that after restarting the iPhone, our application wasn’t able to run. We discovered this error in the log:

Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x146570e0 {NSUnderlyingException=error during prepareSQL for SQL string 'SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'Z_METADATA'' : attempt to write a readonly database, NSSQLiteErrorDomain=264}


We determined that this is a core data bug, if you do not need to call metadataForPersistentStoreOfType you won’t see that there is a problem.  We noticed that this bug occurs only if we use WAL journal mode in SQLite, when we changed it to DELETE journal mode the app worked as expected.

Žádné komentáře:

Okomentovat