アプリケーションを新しいテクノロジ ARC (自動参照カウント) に変換したときに、CoreData からフェッチしたときにエラーが発生しました。以下は私の方法とそれを呼び出すことです:
NSArray *userinfo =[self checkData:self.username];
//This return fault data in array
-(NSArray*) checkData:(NSString*)loginUsername{
id appDelegate = (id)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator:[[appDelegate managedObjectContext] persistentStoreCoordinator]];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *userEntity = [NSEntityDescription entityForName:@"User" inManagedObjectContext:managedObjectContext];
[request setEntity:userEntity];
[request setPredicate:[NSPredicate predicateWithFormat:@"userName == %@",loginUsername ]];
NSError *error;
NSArray *userInfo =[managedObjectContext executeFetchRequest:request error:&error];
//NSLog(@"Number of account%@",[userInfo valueForKey:@"userName"]);
if ([userInfo valueForKey:@"userName"] != nil && userInfo.count != 0)
return userInfo;
else return nil;
}
クラッシュログは次のとおりです。
<User: 0x12b73db0> (entity: User; id: 0x12b6dc20 <x-coredata://7388F0B7-E583-4BF0-BE64-08AD014EC583/User/p2> ; data: <fault>)
2012-12-23 10:09:18.802 test[78839:c07] -[NSNull isEqualToString:]: unrecognized selector sent to instance 0x28ac678
2012-12-23 10:09:18.803 test[78839:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull isEqualToString:]: unrecognized selector sent to instance 0x28ac678'
*** First throw call stack:
(0x277b012 0x2018e7e 0x28064bd 0x276abbc 0x276a94e 0xb4028 0x3e3be 0x1812e59 0x1810f22 0x181216a 0x1810edd 0x1811055 0x175e338 0x5d3a81 0x5d2d33 0x610e3a 0x271d8fd 0x6114bc 0x611435 0x4fb3a0 0x26fef3f 0x26fea39 0x2721734 0x2720f44 0x2720e1b 0x31027e3 0x3102668 0xc5465c 0x2806 0x2735 0x1)
libc++abi.dylib: terminate called throwing an exception