I try to mix non some Core Data objects with Core Data objects, I do this like so with TLIndexPathTools.
- (TLIndexPathDataModel *)controller:(TLIndexPathController *)controller willUpdateDataModel:(TLIndexPathDataModel *)oldDataModel withDataModel:(TLIndexPathDataModel *)updatedDataModel
{
NSMutableArray *sectionInfos = [NSMutableArray array];
TLIndexPathSectionInfo *section0 = [[TLIndexPathSectionInfo alloc] initWithItems:@[@"item1", @"item2"] name:@"section0"];
[sectionInfos addObject:section0];
[sectionInfos addObjectsFromArray:updatedDataModel.sections];
return [[TLIndexPathDataModel alloc] initWithSectionInfos:sectionInfos identifierKeyPath:nil];
}
I am using the TLIndexPathTableViewController and I setup the TLIndexPathController like so:
- (void)setupIndexPathController
{
NSFetchRequest *fetchRequest;
NSString *sectionNameKeyPath;
if (self.product) {
fetchRequest = [SubMenus getSubMenusForProduct:self.product];
sectionNameKeyPath = @"group.name";
}else if (self.cartProduct) {
fetchRequest = [SubMenuProductCart getSubMenusForProductCart:self.cartProduct];
sectionNameKeyPath = @"group.subMenusGroup.name";
}
[TLIndexPathController deleteCacheWithName:@"SubMenuGroupTitles"];
self.indexPathController = nil;
self.indexPathController = [[TLIndexPathController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:sectionNameKeyPath identifierKeyPath:nil cacheName:@"SubMenuGroupTitles"];
NSError *error;
[self.indexPathController performFetch:&error];
}
This setup method gets called in my viewDidAppear inorder to fetch and refresh the objects.
But when I call [self.indexPathController.dataModel itemAtIndexPath:indexPath]; in my DidSelectRow method I get the following crash:
CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array with userInfo