I'm doing the second part of Ray Wenderlich's Core Data Tutorial. Instead of reading the file that contains the default data, I'm trying to read the actual Failed Bank datafile that was created in his SQLite3 tutorial. The program is throwing an exception when I try to create the Store and open the File.
Here is the code snippet
- (NSPersistentStoreCoordinator *) persistentStoreCoordinator
{
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"banklist.sqlite3"];
if (![[NSFileManager defaultManager] fileExistsAtPath:[storeURL path]]) {
NSURL *preloadURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"banklist" ofType:@"sqlite3"]];
NSError *err = nil;
if (![[NSFileManager defaultManager] copyItemAtURL:preloadURL toURL:storeURL error:&err]) {
NSLog(@"Opps, couldn't copy preloaded data");
}
}
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
}
Here is the exception:
2013-09-16 20:19:57.549 FailedBankCD[4086:c07] CoreData: error: (1) I/O error for database at /Users/artletter1/Library/Application Support/iPhone Simulator/6.1/Applications/524B84E3-94D6-40A3-8847-DD15A99B22A2/Documents/banklist.sqlite3. SQLite error code:1, 'no such table: Z_METADATA' 2013-09-16 20:19:57.552 FailedBankCD[4086:c07] Unresolved error Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x854b560 {NSUnderlyingException=I/O error for database at /Users/artletter1/Library/Application Support/iPhone Simulator/6.1/Applications/524B84E3-94D6-40A3-8847-DD15A99B22A2/Documents/banklist.sqlite3. SQLite error code:1, 'no such table: Z_METADATA', NSSQLiteErrorDomain=1}, { NSSQLiteErrorDomain = 1; NSUnderlyingException = "I/O error for database at /Users/artletter1/Library/Application Support/iPhone Simulator/6.1/Applications/524B84E3-94D6-40A3-8847-DD15A99B22A2/Documents/banklist.sqlite3. SQLite error code:1, 'no such table: Z_METADATA'"; }
Thanks!
Roy