我正在使用以下方法从核心获取数据。我的应用冻结了
NSArray *fetchResult = [self.managedObjectContext executeFetchRequest:request error:&error];
有时它有效,有时它只是冻结而没有错误消息或崩溃。当我暂停调试器时,它停在上面的代码行!我不使用线程也不使用块。
-(NSArray *)getSubContent
{
NSEntityDescription *desc;
NSPredicate *predicate;
NSSortDescriptor *sortDescriptor;
switch ([tableSelector selectedSegmentIndex])
{
case 0: //fav list
desc = [NSEntityDescription entityForName:@"Contact" inManagedObjectContext:self.managedObjectContext];
predicate = [NSPredicate predicateWithFormat:@"isFavorite = %@",[NSNumber numberWithBool:YES]];
sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
break;
case 1: //Rassayel list
desc = [NSEntityDescription entityForName:@"Contact" inManagedObjectContext:self.managedObjectContext];
sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
predicate = [NSPredicate predicateWithFormat:@"isApp = %@",[NSNumber numberWithBool:YES]];
break;
case 2: //group list
desc = [NSEntityDescription entityForName:@"Group" inManagedObjectContext:self.managedObjectContext];
predicate = nil;
sortDescriptor = nil;
break;
default:
break;
}
NSFetchRequest *request = [[NSFetchRequest alloc] init] ;
[request setEntity:desc];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[request setPredicate:predicate];
NSError *error = nil;
NSArray *fetchResult = [self.managedObjectContext executeFetchRequest:request error:&error];
if ( error )
NSLog(@"%@",error);
return fetchResult;
}
CRASH LOG
异常类型:00000020例外代码:0x8badf00d突出显示的主题:0
特定应用信息:com.takarub.rasayl无法启动 及时
经过的总CPU时间(秒):1.620(用户1.620,系统0.000),3% CPU Elapsed应用程序CPU时间(秒):0.432,1%CPU
线程0名称:Dispatch queue:com.apple.main-thread
线程0:
0 libsystem_kernel.dylib 0x32b800d8 __psynch_mutexwait + 24
1 libsystem_c.dylib 0x34eaa674 pthread_mutex_lock + 376
2 CoreData 0x327dbd52 - [_ PFLock lock] + 18
3 CoreData 0x327eb1f2 - [NSPersistentStoreCoordinator executeRequest:withContext:error:] + 806
4 CoreData 0x327e9c22 - [NSManagedObjectContext executeFetchRequest:error:] + 598
5 RassayelV1.0 0x000193ec - [ContactsViewController getSubContent](ContactsViewController.m:225)