I am trying to edit a mutable array from a property and can t seem to directly make it work. Consider the following code that seems to work, but seems also very inefficient; I have to copy the whole property array just to make a change in one object. Why can I change the whole "carNames" array, but can t make a change to one of it s objects?
Thank you for any light you might be able to provide...
// CarTableViewController.h
// ...
@interface CarTableViewController : UITableViewController {
NSMutableArray *carNames;
}
@property (nonatomic, retain) NSMutableArray *carNames;
-(IBAction)addCarButton:(id)sender;
// ...
// --------------------------------------
// -------CarTableViewController.m-------
// ...
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Could I somehow run the removeOjectAtIndex:
// directly on the carNames Property? - this code works...
NSMutableArray *mutablecarNames = [carNames mutableCopy];
[mutablecarNames removeObjectAtIndex:indexPath.row];
carNames = [mutablecarNames copy];
[mutablecarNames release];
// This code doesn t work... Why?
// [carNames removeObjectAtIndex:indexPath.row];
}
// ...