3

我正在使用以下方法从核心获取数据。我的应用程序冻结

      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;

}



崩溃日志

异常类型:00000020 异常代码:0x8badf00d 突出显示的线程:0

应用程序特定信息:com.takarub.rasayl 未能及时启动

已用总 CPU 时间(秒):1.620(用户 1.620,系统 0.000),3% CPU 已用应用程序 CPU 时间(秒):0.432,1% CPU

线程 0 名称:调度队列:com.apple.main-thread

线程 0:

0 libsystem_kernel.dylib 0x32b800d8 __psynch_mutexwait + 24

1 libsystem_c.dylib 0x34eaa674 pthread_mutex_lock + 376

2 核心数据 0x327dbd52 -[_PFLock 锁定] + 18

3 核心数据 0x327eb1f2-[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 806

4 CoreData 0x327e9c22-[NSManagedObjectContext 执行FetchRequest:错误:] + 598

5 RassayelV1.0 0x000193ec-[ContactsViewController getSubContent] (ContactsViewController.m:225)

4

0 回答 0