我使用CoreData並執行以下命令返回的對象的數量:CoreData的形式findAll返回一個對象,但簡單fetchRequest不會返回0對象
[Contact findAll];
然而,當我建立一個簡單的NSFetchrequest
像這樣,我得到0個對象。
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
fetchRequest.entity = [NSEntityDescription entityForName:@"Contact" inManagedObjectContext:self.context];
fetchRequest.sortDescriptors = [NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES]];
self.fetchedResultsController = [[NSFetchedResultsController alloc]
initWithFetchRequest:fetchRequest
managedObjectContext:self.context
sectionNameKeyPath:nil
cacheName:nil];
NSError *error;
NSArray *array = [self.context executeFetchRequest:fetchRequest error:&error];
請告訴我我在做什麼錯在這裏。由於我沒有Predicate集,我期望獲得相同數量的對象,但是我得到一個包含0個對象和error = nil
的數組。請注意0不是零。
你得到一個空陣列,還是你什麼都沒有得到? – Jim 2012-04-25 11:55:00
@Jim:我得到一個空數組。我更新了答案,使其更加清晰。 – Besi 2012-04-25 11:56:17
定義了'findAll'方法在哪裏?我不認爲它是核心數據的標準部分。 – Jim 2012-04-25 12:13:07