when I try to set the variable eventId of my NSManagedObject (Event) I get ther error EXC_BAD_ACCESS.
I don’t know the reason.
Here’s the code of my class Event
@interface Event : NSManagedObject
@property (assign) NSInteger eventId;
@end
@interface Event (PrimitiveAccessors)
- (NSInteger)primitiveEventId;
- (void)setPrimitiveEventId:(NSInteger)event_id;
@end
@implementation Event
@dynamic eventId;
...
-(NSInteger)eventId
{
[self willAccessValueForKey:@"eventId"];
NSInteger id = [self eventId];
[self didAccessValueForKey:@"eventId"];
return id;
}
-(void)setEventId:(NSInteger)event_id
{
[self willChangeValueForKey:@"eventId"];
[self setPrimitiveEventId:event_id]; //Here I get the error
[self didChangeValueForKey:@"eventId"];
}
...
Anyone can solve the problem?
Thanks for help
If you look closely at the documentation, you’ll see that the primitive accessor methods for the scalar attribute
double lengthin the example still useNSNumber *arguments and return values:[Note: I added the
*that was missing in the original code snippet in Apple’s documentation.]So try declaring your primitive accessors with
NSNumber *arguments and return values.Or if you really must, consider implementing your own primitive accessor methods.