I'm currently trying to write my first CoreData project, and I'm very confused. I use the following code to configure the resulting result controller:
- (NSFetchedResultsController *)fetchedResultsController { if (_fetchedResultsController != nil) return _fetchedResultsController; Singleton *singleton = [Singleton sharedSingleton]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"MapEntity" inManagedObjectContext:[singleton managedObjectContext]]; [fetchRequest setEntity:entity]; NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"sName" ascending:NO]; [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]]; [fetchRequest setFetchBatchSize:8];
I put in an NSLog to see if fetchRequest found the results, and it does:
2013-01-28 11:20:14.735 WildMap_iOS[10931:16a03] Maps present in database: UK Capital Cities 2013-01-28 11:20:14.736 WildMap_iOS[10931:16a03] Maps present in database: The UK 2013-01-28 11:20:14.736 WildMap_iOS[10931:16a03] Maps present in database: Testing123 2013-01-28 11:20:14.736 WildMap_iOS[10931:16a03] Maps present in database: TestForPic 2013-01-28 11:20:14.736 WildMap_iOS[10931:16a03] Maps present in database: Scottish Map 2013-01-28 11:20:14.736 WildMap_iOS[10931:16a03] Maps present in database: Old Scotland 2013-01-28 11:20:14.736 WildMap_iOS[10931:16a03] Maps present in database: Old Scotland 2013-01-28 11:20:14.737 WildMap_iOS[10931:16a03] Maps present in database: Old Scotland 2013-01-28 11:20:14.737 WildMap_iOS[10931:16a03] Maps present in database: Field Concatination
However, when I try to use my fetchedResultsController to set up my tableView numberOfRowsInSection as follows:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { id sectionInfo = [[_fetchedResultsController sections] objectAtIndex:section]; return [sectionInfo numberOfObjects]; }
"return [sectionInfo numberOfObjects];" returns nil, although fetchRequest seems to be great for objects.
I used this code in order, however, I recently added an integer to mapEntity (iID), and this made me delete the simulator data as the structure of the saved data changes. After I deleted the data and restarted the application, the code no longer works.
Can someone help me understand why this is happening? I donβt think this is a naming convention as it was before, and fetchRequest returns the results.
source share