当用户摇动设备时,我试图检测我在 Core Data 中拥有的对象数量。当我尝试在 motionEnded: 中调用 NSFetchRequest 时,模拟器在 main 处因未知错误而崩溃。
在motionEnded内部进行这样的提取:可能吗?
我到目前为止的代码:
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
// see if we have albums to upload
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Groups" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSUInteger group_count = [managedObjectContext countForFetchRequest:fetchRequest error:nil];
if (group_count == 0)
{
// show alertview
}
else
{
// show another alertview
}
}