2

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'";

5
  • 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? Commented Jul 17, 2015 at 12:21
  • 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? Commented Jul 17, 2015 at 12:36
  • 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 filename Commented Jul 17, 2015 at 12:38
  • 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. Commented Jul 17, 2015 at 12:41
  • 1
    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. Commented Jul 17, 2015 at 12:45

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.