0
這是我的代碼中插入數據如何從核心數據庫獲取數據
NSError *error;
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
newtext = [NSEntityDescription insertNewObjectForEntityForName:@"TableTextView" inManagedObjectContext:context];
//NSData *bytes = [txtView.text dataUsingEncoding:NSUTF8StringEncoding];
NSMutableArray *arr = [[NSMutableArray alloc] init];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:txtView.text forKey:@"FileString"];
[arr addObject:dict];
NSData *bytes1 = [NSKeyedArchiver archivedDataWithRootObject:arr];
[newtext setValue:bytes1 forKey:@"textView"];
[context save:&error];
現在我想取我已經發送到核心數據庫 所以我用這個代碼來做到這一點
數據NSError *errorr;
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
NSManagedObjectContext *managedObjectContext = [appDelegate managedObjectContext ];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"TableTextView" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects;
fetchedObjects = [managedObjectContext executeFetchRequest:fetchRequest error:&errorr];
for (int i =0; i <[fetchedObjects count]; i++){
newtext = [fetchedObjects objectAtIndex:i];
strvalue = [NSString stringWithFormat:@"%@",[newtext valueForKey:@"textView"]];
NSLog(@"====%@",strvalue);
NSData *data=[strvalue dataUsingEncoding:NSUTF8StringEncoding];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSLog(@"=====%@",unarchiver);
現在的問題這段代碼拋出異常我調試的時候來上NSKeyedUnarchiver.and的例外是
2013-05-28 15:13:33.030 DocumentTouch[2376:c07] -[__NSCFData objectForKey:]: unrecognized selector sent to instance 0x8620ad0
2013-05-28 15:13:33.031 DocumentTouch[2376:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData objectForKey:]: unrecognized selector sent to instance 0x8620ad0'
*** First throw call stack:
(0x1787012 0x15ace7e 0x18124bd 0x1776bbc 0x177694e 0x16fbe18 0xfdc9b8 0x3e62 0x15c0705 0x4f7920 0x4f78b8 0x5b8671 0x5b8bcf 0x5b7d38 0x52733f 0x527552 0x5053aa 0x4f6cf8 0x2502df9 0x2502ad0 0x16fcbf5 0x16fc962 0x172dbb6 0x172cf44 0x172ce1b 0x25017e3 0x2501668 0x4f465c 0x26dd 0x2605 0x1)
libc++abi.dylib: terminate called throwing an exception
任何人都可以請幫我解決這個問題......