我正在使用CoreData并可以使用[MyManagedObjectClass findAll]
检索我的对象。现在,我想用一个NSFetchRequest
它看起来像这样获取的一些数据:NSFetchRequest与'findAll'相比有不同的结果
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
fetchRequest.entity = [NSEntityDescription entityForName:@"Contacts" inManagedObjectContext:self.context];
fetchRequest.sortDescriptors = [NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES]];
NSError *error;
NSArray *array = [self.context executeFetchRequest:fetchRequest error:&error];
虽然我没有一个谓语,请求不返回所有的对象,但0对象,而不是。 AFAIK我不需要有谓词,如果我想加载所有的对象,对吧?
他们都似乎没问题:self.context被初始化,并且错误是无 – Besi 2012-03-02 13:56:35
,你肯定有实体“联系人”实际上在您的数据库中? – user1226119 2012-03-02 14:05:40
self.context不是零,但它是错误的上下文。看到我自己的答案 – Besi 2012-05-09 13:47:07