Q: Delete table row and at the same time object from core data with one button I have a core data model with single entity objects. Then i load these objects into an array and display them in a table with default cell styles. In the navigation bar there is a delete button that when a row is selected (e.g. object) and this button clicked, it should delete the row and the respective object in the core model. I have seen examples of deleting rows but with a delete button displayed in each row. I want to have only one button in the navig bar and be able to control the deleting of rows from it. I have tried the code below but it does not work. I can't find a way to make it identify the row selected in the delete method. Any help is appreciated.
In viewdidload of the tableviewcontroller class:
 UIBarButtonItem *delButton = [[UIBarButtonItem alloc]
                                  initWithTitle:@"Del"
                                  style: UIBarButtonItemStyleBordered
                                  target: self
                                  action:@selector(delItemToArray)];


self.managedObjectContext = ((ecoAppDelegate *) [UIApplication sharedApplication].delegate).managedObjectContext;



NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
                               entityForName:@"FavoritesInfo" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];

fetchRequest.resultType = NSDictionaryResultType;

[fetchRequest setPropertiesToFetch:[NSArray arrayWithObjects:@"name", nil]];



  NSError *error=nil;

self.favArr=[self.managedObjectContext executeFetchRequest:fetchRequest error:&error];


if (error!=nil) {
    NSLog(@" fetchError=%@,details=%@",error,error.userInfo); 
}


self.favName = [self.favArr valueForKey:@"name"];




//Delete Item To table array and delete object to data core model

    - (void)delItemToArray {

        AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

        NSManagedObjectContext *context = [appDelegate managedObjectContext];

        [context deleteObject:appDelegatee.favoritesInfo]; // favoritesInfo is the NSManagedObject

        NSIndexPath *indexPath;
        [favName removeObjectAtIndex:indexPath.row];

        [appDelegatee saveContext]; // to save changes in the core data model

        [self.tableView reloadData];
    }

Error:
  [__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0x8852b90
    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0x8852b90'


A: You might got a warning like Incompatible pointer types initializing 'NSMutableArray *' with an expression of type 'NSArray *' here
self.favArr=[self.managedObjectContext executeFetchRequest:fetchRequest error:&error];

You should make the fetched array mutable for removing objects from it. You can do it like
self.favArr  = [[self.managedObjectContext executeFetchRequest:fetchRequest error:&error] mutableCopy];

Also change this
self.favName = [self.favArr valueForKey:@"name"];

to
self.favName = [[self.favArr valueForKey:@"name"]mutableCopy];

