2
votes

I am new to Core Data and have followed a few tutorials. However I don't seem to be able to access the .sqlite file either on the simulator or on my iPhone 6. The debugger prints the following. Can anyone provide any assistance please?

2015-07-17 11:31:28.006 Rockford[390:32594] CoreData: error: (1) I/O error for database at /var/mobile/Containers/Data/Application/D2A80335-E681-4194-944D-CAE66F80EFA6/Documents/Rockford.sqlite. SQLite error code:1, 'unknown database ZROCKFORD'
2015-07-17 11:31:28.011 Rockford[390:32594] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Containers/Data/Application/D2A80335-E681-4194-944D-CAE66F80EFA6/Documents/Rockford.sqlite options:{ NSInferMappingModelAutomaticallyOption = 1; NSMigratePersistentStoresAutomaticallyOption = 1; } ... returned error Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x170460a40 {NSSQLiteErrorDomain=1, NSUnderlyingException=I/O error for database at /var/mobile/Containers/Data/Application/D2A80335-E681-4194-944D-CAE66F80EFA6/Documents/Rockford.sqlite. SQLite error code:1, 'unknown database ZROCKFORD'} with userInfo dictionary { NSSQLiteErrorDomain = 1; NSUnderlyingException = "I/O error for database at /var/mobile/Containers/Data/Application/D2A80335-E681-4194-944D-CAE66F80EFA6/Documents/Rockford.sqlite. SQLite error code:1, 'unknown database ZROCKFORD'";

1
Does the sqlite file mentioned in the error actually exist? I wonder if the problem is the app being unable to open the file rather than create it? Can you post the code which initialises your persistentStoreCoordinator?John Martin
Just doing this in the viewDidLoad let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext is enough to cause the error. How do I check if the sqlite file has been created?Jon Farmer
You mention it doesn't work on the simulator - so If you run it on the simulator, the error is giving you the full path to the file that it's trying to open. You can see if the file exists from the command line, or in Finder, press Cmd+Shift+G and paste in the filenameJohn Martin
OK if I run the simulator I see the Rockford.sqlite file on my Mac in the dir path the console output said it was looking for it.Jon Farmer
Aha, looks like I have fixed it I deleted the .sqlite file and then deleted the Entity. Re-created the Entity and it all worked. Thanks for your help.Jon Farmer

1 Answers

1
votes

Just delete the App from the simulator/device and run it again. It may happen when you make some changes in core data part of your project and the device have the previously created database.