5

I've seen other posts regarding unrecognized selector errors, but nothing regarding the auto-generated code in the following method:

- (void)tableView:(UITableView *)tableView commitEditingStyle:forRowAtIndexPath:

This is called when I swipe to delete, and when I tap the delete button I get the following error:

-[Vehicle removeObjectFromGasUpsAtIndex:]: unrecognized selector sent to instance 0x8172c60

My NSManagedObject class, Vehicle, has a NSOrderedSet variable named gasUps that should respond to this message when I want to delete it. Or so I thought.

Here is the entire method where it is crashing:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
   if (editingStyle == UITableViewCellEditingStyleDelete) {
    // need to delete gas up and not vehicle
    int row = [indexPath row];

    //[self.selectedVehicle removeObjectFromGasUpsAtIndex:row];
    [self.selectedVehicle removeObjectFromGasUpsAtIndex:row];
    NSError *error = nil;
    if (![self.managedObjectContext save:&error]) {
         // Replace this implementation with code to handle the error appropriately.
         // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }
 }   
}

Why is this selector unrecognized?

EDIT: this is for Jody.

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

typedef enum {
    FullExtract,
    NameExtract
} kTitleExtract;

@interface Vehicle : NSManagedObject

@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * year;
@property (nonatomic, retain) NSString * make;
@property (nonatomic, retain) NSNumber * mileage;
@property (nonatomic, retain) NSString * model;
@property (nonatomic, retain) NSOrderedSet *gasUps;

// added methods
- (NSString *)getTitleExtract:(kTitleExtract)titleExtract;

@end

@interface Vehicle (CoreDataGeneratedAccessors)

- (void)insertObject:(NSManagedObject *)value inGasUpsAtIndex:(NSUInteger)idx;
- (void)removeObjectFromGasUpsAtIndex:(NSUInteger)idx;
- (void)insertGasUps:(NSArray *)value atIndexes:(NSIndexSet *)indexes;
- (void)removeGasUpsAtIndexes:(NSIndexSet *)indexes;
- (void)replaceObjectInGasUpsAtIndex:(NSUInteger)idx withObject:(NSManagedObject *)value;
- (void)replaceGasUpsAtIndexes:(NSIndexSet *)indexes withGasUps:(NSArray *)values;
- (void)addGasUpsObject:(NSManagedObject *)value;
- (void)removeGasUpsObject:(NSManagedObject *)value;
- (void)addGasUps:(NSOrderedSet *)values;
- (void)removeGasUps:(NSOrderedSet *)values;

@end

And here is the snippet of code where self.selectedVehicle is set:

if (self.vehiclesArray != nil  && [self.vehiclesArray count] != 0 && self.vehicleIndex != -1) {
    // enable add buttom
    [self.navigationItem.rightBarButtonItem setEnabled:YES];
    self.selectedVehicle = [self.vehiclesArray objectAtIndex:self.vehicleIndex];
    NSLog(@"set selected vehicle");
} else {
    // disable add button
    [self.navigationItem.rightBarButtonItem setEnabled:NO];

    // set vehicle defaults to -1 and make disable add buttom
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setInteger:-1 forKey:@"vehicleIndex"];
    [defaults synchronize];
    NSLog(@"set index to -1");
}
kschins
  • 1,054
  • 1
  • 13
  • 26
  • You basically provided no helpful information. Just an error, and a line of code. Basically no other context. We are not mind readers. All we can tell you is the same as the runtime: your object does not recognize the selector `removeObjectFromGasUpsAtIndex`. Now, if you want to show the code that defines the `Vehicle` type, and how you are setting `self.selectedVehicle` and maybe even a log of the object right before sending it the message... then maybe you could get some help. – Jody Hagins Sep 12 '12 at 01:12
  • possible duplicate of [Exception thrown in NSOrderedSet generated accessors](http://stackoverflow.com/questions/7385439/exception-thrown-in-nsorderedset-generated-accessors) – jrturton Sep 12 '12 at 06:04

1 Answers1

5

This is probably related to a known bug in the Core Data auto generated accessors for ordered one-to-many relationships.

rdar://10114310

Until this is addressed you need to provide your own implementation for the missing accessors.

See answers to this question

Community
  • 1
  • 1
FluffulousChimp
  • 9,157
  • 3
  • 35
  • 42