SpokaneDude
SpokaneDude

Reputation: 4984

Unrecognized selector sent to Core Data causes app crash

I have a iPad app, using XCode 4.5, Storyboards, iOS 6 and MagicalRecord. This code is causing the error, and I don't see why. Both aApptStart and selectedStartDate are defined as DateTime. So, what is causing this?

Here is the offending code:

- (IBAction)saveAppointment:(UIButton *)sender {

    NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
    AppointmentInfo *newAppointment = [AppointmentInfo createEntity];  //  create the entity

    NSLog(@"Selected start Date (save): %@", [self formatSelectedDate: selectedStartDate]); 

    newAppointment.aApptStart = selectedStartDate;  //  <------  causing the error
    newAppointment.aApptEnd= selectedEndDate;
    newAppointment.aTech = selectedTech;

    [localContext MR_saveNestedContexts];
}

Here is the error I'm getting:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject setAApptStart:]: unrecognized selector sent to instance 0xee85dd0'

Upvotes: 1

Views: 1015

Answers (2)

Hermann Klecker
Hermann Klecker

Reputation: 14068

Aparently your [AppointmentInfo createEntity] does not return an object of type AppointmentInfo but NSManagedObject and NSManagedObject does not provide a selector for setAApptStart meaning no setter for a propery aApptStart.

How exactly does your +(AppointmentInfo*) createEntity look like?

Upvotes: 0

Mario
Mario

Reputation: 4520

So, what is causing this?

The error indicates that there is no property of that name in AppointmentInfo.

Well, does your NSManagedObject subclass (AppointmentInfo) declare the property aApptStart? Also, does a corresponding attribute for your entity exist (if the property is implemented @dynamically)?

I guess it would.... Maybe a typo? Can you show interface and implementation of AppointmentInfo?

Upvotes: 4

Related Questions