0

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
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • This might be unrelated but have you recently changed your datamodel file? if so try erasing the app completely from simulator/test device and re-compile/install/run. – Enzo Jul 09 '14 at 16:30
  • Sorry, I just saw this (I'm the author of TLIPT). Off the top of my head, I can't see how this error could be caused by TLIPT (it does not observe the `NSManagedObjectContextObjectsDidChangeNotification` notification). Can you post the full stack trace? – Timothy Moose Jul 30 '14 at 08:43

1 Answers1

0

The crash seems like your accessing the empty array. So always check the nil and count greater than zero condition in the array for make sure that crash should not occur. And also check before adding object to array, you have been initialize the array or not. Otherwise it will never add any object

Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56