我一直在尝试将 Core Data 添加到我现有的 iOS 项目中。我没有现有的 sql 数据库,但我创建了一个数据模型。我遵循以下教程:http ://wiresareobsolete.com/wordpress/2009/12/adding-core-data-existing-iphone-projects/
它在以下代码中产生错误:
(NSPersistentStoreCoordinator *) persistentStoreCoordinator{
if (persistentStoreCoordinator != nil){
return persistentStoreCoordinator;
}
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentDirectory]
stringByAppendingPathComponent: @"MyPOC.sqlite"]];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]){
NSLog(@"Unresolved error OH NO %@, %@", error, [error userInfo]);
}
return persistentStoreCoordinator;
}
我收到以下错误:
2012-10-25 13:52:29.156 MyPOC[1994:11603] Unresolved error OH NO Error
Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed.
(Cocoa error 512.)" UserInfo=0x8246240 {reason=Failed to create file; code = 2},
{reason = "Failed to create file; code = 2";}
我真的不知道它为什么会崩溃以及如何解决它。如果需要更多信息来帮助,请告诉我。