【发布时间】:2011-08-11 16:48:45
【问题描述】:
目前在我的核心数据保存中发现了一个问题。由于某种原因,一个 NSString 没有被正确保存,无论如何总是返回 0 。以下是我当前的代码。
appDelegate =(NotaciousAppDelegate *) [[UIApplication sharedApplication] delegate];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Note" inManagedObjectContext:appDelegate.managedObjectContext];
NSArray *fetchedNotes;
NSArray *notes = [object valueForKey:@"result"];
for (NSDictionary *singleNote in notes){
noteFetch=[[NSFetchRequest alloc] init];
[noteFetch setEntity:entity];
NSPredicate *pred=[NSPredicate predicateWithFormat:@"ID==%@",[singleNote objectForKey:@"note id"]];
[noteFetch setPredicate:pred];
NSError *fetchError=nil;
fetchedNotes=[appDelegate.managedObjectContext executeFetchRequest:noteFetch error:&fetchError];
if (fetchError!=nil) {
NSLog(@"syncNotes fetchError=%@,details=%@",fetchError,fetchError.userInfo);
}
if ([fetchedNotes count]==0) {
NSString *notelocked = [singleNote objectForKey:@"note locked"];
NSString *notecreated = [singleNote objectForKey:@"note created"];
NSString *noteupdated = [singleNote valueForKey:@"note updated"];
NSString *notetitle = [singleNote objectForKey:@"note title"];
NSString *notesummary = [singleNote objectForKey:@"note summary"];
NSString *noteid = [singleNote objectForKey:@"note id"];
NSString *notecontent = [singleNote objectForKey:@"note content"];
NSString *formattedTitle = [NSString decodeShit:notetitle];
NSString *formattedSummary = [NSString decodeShit:notesummary];
NSString *formattedContent = [NSString decodeShit:notecontent];
NSLog(@"Note Title: %@",formattedTitle);
NSLog(@"Note Summary: %@",formattedSummary);
NSLog(@"Note ID: %@",noteid);
NSLog(@"Note Content: %@",formattedContent);
NSLog(@"Note Created: %@",notecreated);
NSLog(@"Note Updated: %@",noteupdated);
NSLog(@"Note Locked: %@",notelocked);
newNote = [NSEntityDescription insertNewObjectForEntityForName:@"Note" inManagedObjectContext:appDelegate.managedObjectContext];
[newNote autorelease];
[newNote setValue:formattedContent forKey:@"content"];
[newNote setValue:formattedSummary forKey:@"summary"];
[newNote setValue:formattedTitle forKey:@"title"];
[newNote setValue:noteid forKey:@"ID"];
[newNote setValue:notecreated forKey:@"created"];
[newNote setValue:noteupdated forKey:@"updated"];
[newNote setValue:notelocked forKey:@"locked"];
NSLog(@"Note Updated in MOC:%@",[newNote valueForKey:@"updated"]);
NSError *error = nil;
if (![appDelegate.managedObjectContext save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
[noteFetch release];
}
尝试保存 updated 字符串时会出现问题。出于某种原因,无论那里有什么字符串,它都不会保存到 Core Data 属性中。
我正在努力寻找任何连贯的理由让它不保存,但我认为这是可能的。这是此应用程序上架之前需要排序的最后一个问题。任何帮助都会很棒!
编辑
没有错误,调试控制台中只有以下输出。
2011-04-24 10:53:22.815 Notacious[5660:707] Note Title: Hello there!
2011-04-24 10:53:22.816 Notacious[5660:707] Note Summary:
2011-04-24 10:53:22.817 Notacious[5660:707] Note ID: 1240
2011-04-24 10:53:22.817 Notacious[5660:707] Note Content: Hello there!
This is a new note made from the iPhone client. Woot?
2011-04-24 10:53:22.818 Notacious[5660:707] Note Created: Thu Apr 21 19:19:39 -0700 2011
2011-04-24 10:53:22.819 Notacious[5660:707] Note Updated: Thu Apr 21 19:19:39 -0700 2011
2011-04-24 10:53:22.820 Notacious[5660:707] Note Locked: 0
2011-04-24 10:53:22.823 Notacious[5660:707] Note Updated in MOC:0
【问题讨论】:
-
您发现有什么错误吗?
-
将控制台的输出添加到问题中。
标签: iphone objective-c cocoa-touch core-data nsstring