Arp*_*ekh 1 iphone xcode cocoa-touch core-data objective-c
在我的申请中
我有一个sqlite文件CoreDataBountyHunter.sqlite
我正在使用核心数据对象模型来连接此sqlite文件.
因为它是Basic应用程序,所以在获取数据或实际代码部分之前我遇到了错误.我有错误像持久存储协调器无法连接到文件或模型.
1)访问视图将出现部分NSManagedObjectContext*moc = appDelegate.managedObjectContext.部分来自于它
2)显示文件的一些代码存在
3)然后它转到持久性存储协调器的下面代码,它从中调用管理对象模型的功能,该代码存在于下一个代码中...在if条件下返回到持久协调器后它出现错误并中止所以请救命
-
//1--------
(NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil)
{
return __persistentStoreCoordinator;
}
NSURL *storeURL=[[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreDataBountyHunter.sqlite"];
NSLog(@"%@",storeURL);
NSError *error = nil;
**__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])**
{
Typical reasons for an error here include:
* The persistent store is not accessible;
* The schema for the persistent store is incompatible with current managed object model.
Check the error message to determine what the actual problem was.
[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
**abort();** I have error at this place
} ``
return __persistentStoreCoordinator;
}
enter code here
- (NSManagedObjectModel *)managedObjectModel
{
if (__managedObjectModel != nil)
{
return __managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"CoreDataBountyHunter" withExtension:@"momd"];
__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return __managedObjectModel;
}
//-------------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
实际上,核心数据如何使用不同的路径来读取写入数据是完全混乱所以请解释.谢谢我为什么在这个地方收到错误.因此,在访问了管理对象模型代码之后,它将转向持久的协调器,因此在这个位置它应该有一些......