使用書籍教程,其他3個持久性方法完美無缺地工作。核心數據持久性,未解決的錯誤
2012-06-01 23:50:52.555核心數據持久性[9022:FB03]未解決 錯誤錯誤域= NSCocoaErrorDomain代碼= 134100「的操作 無法完成運行時模擬器收到此消息。(Cocoa error 134100.)「UserInfo = 0x6b92af0 {metadata = {type = immutable dict, count = 7,entries => 2:{contents = 」NSStoreModelVersionIdentifiers「} = {type = immutable,count = 1,values = {0:{contents =「」})} 4:{contents =「NSPersistenceFrameworkVersion」} = {value = +386,type = kCFNumberSInt64Type} 6: {contents = 「NSStoreModelVersionHashes」} = {type = immutable dict, count = 1,entr IES => 1: {內容= 「線」} = {長度= 32,容量= 32,字節= 0x03913bef8e6d277b9119a99fbc7b4adc ... 39db5d5f94ed5507}} 7: {內容= 「NSStoreUUID」} = {內容= 「FE367DDA -4009-4CD1-9B8A-D62943668E8E「} 8:{contents =」NSStoreType「} = {contents =」SQLite「} 9:{contents =」_NSAutoVacuumLevel「} = {contents =」2「} 10:{contents =」 NSStoreModelVersionHashesVersion「} = {值= 3,類型= kCFNumberSInt32Type}},原因=用來打開存儲該模型是 與用於創建存儲}的一個不兼容,{ 元數據= { NSPersistenceFrameworkVersion = 386; NSStoreModelVersionHashes = { 行= < 03913bef 8e6d277b 9119a99f bc7b4adc 4fec730a 73b61247 39db5d5f 94ed5507>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers =( 「」 ); NSStoreType = SQLite; NSStoreUUID =「FE367DDA-4009-4CD1-9B8A-D62943668E8E」; 「_NSAutoVacuumLevel」= 2; }; reason =「用於打開商店的模型與用於創建商店的模型不兼容」; }
我的兩個實體設置正確,這裏是我的文件:
#import "BIDViewController.h"
#import "BIDAppDelegate.h"
@interface BIDViewController()
@end
@implementation BIDViewController
@synthesize line1;
@synthesize line2;
@synthesize line3;
@synthesize line4;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
BIDAppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription
entityForName:@"Line"
inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
NSError *error;
NSArray *objects = [context executeFetchRequest:request error:&error];
if (objects == nil) {
NSLog(@"There was an error!");
// Do whatever error handling is appropriate
}
for (NSManagedObject *oneObject in objects) {
NSNumber *lineNum = [oneObject valueForKey:@"lineNum"];
NSString *lineText = [oneObject valueForKey:@"lineText"];
NSString *fieldName = [NSString
stringWithFormat:@"line%d", [lineNum integerValue]];
UITextField *theField = [self valueForKey:fieldName];
theField.text = lineText;
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification
object:app];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.line1 = nil;
self.line2 = nil;
self.line3 = nil;
self.line4 = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)applicationWillResignActive:(NSNotification *) notification {
BIDAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSError *error;
for (int i = 1; i <=4; i++) {
NSString *fieldName = [NSString stringWithFormat:@"line%d", i];
UITextField *theField = [self valueForKey:fieldName];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entityDescription = [NSEntityDescription
entityForName:@"Line"
inManagedObjectContext:context];
[request setEntity:entityDescription];
NSPredicate *pred = [NSPredicate
predicateWithFormat:@"(lineNum = %d)", i];
[request setPredicate:pred];
NSManagedObject *theLine = nil;
NSArray *objects = [context executeFetchRequest:request
error:&error];
if (objects == nil) {
NSLog(@"There was an error!");
// Do whatever error handling is appropriate
}
if ([objects count] > 0)
theLine = [objects objectAtIndex:0];
else
theLine = [NSEntityDescription
insertNewObjectForEntityForName:@"Line"
inManagedObjectContext:context];
[theLine setValue:[NSNumber numberWithInt:i] forKey:@"lineNum"];
[theLine setValue:theField.text forKey:@"lineText"];
}
[context save:&error];
}
@end
任何想法或意見讚賞!
哦,這個Redbull男人不會踢!是的,我實際上改變了我的實體屬性的類型,修復了導致此錯誤的一個錯誤。刪除應用程序並重新啓動模擬器運行完美。感謝您的快速幫助! – Devj
查看輕量級遷移選項。 –