これを使用してsqliteDBをアプリケーションに追加しようとしています:CoreData:iOSアプリにデータをプリロードします
チュートリアルに続いて、私は問題にぶつかりました:
[NSFileManager copyItemAtPath:toPath:error:]: source path is nil
私は次のコードを使用します:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (__persistentStoreCoordinator != nil) {
return __persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Peter_R0_1.sqlite"];
if(![[NSFileManager defaultManager] fileExistsAtPath:[storeURL path]]) {
NSString *sqlitePath = [[NSBundle mainBundle] pathForResource:@"Peter_R0_1" ofType:@"sqlite" inDirectory:nil];
NSError *anyError = nil;
BOOL success = [[NSFileManager defaultManager] copyItemAtPath:sqlitePath toPath:[storeURL path] error:&anyError];
}
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;
}
この問題について助けていただければ幸いです