I created a custom class object Action with three enums as instance variables:
@interface Action : NSObject <NSCopying>
@property ImageSide imageSide; //typedef enum
@property EyeSide eyeSide; //typedef enum
@property PointType pointType; //typedef enum
@property int actionId;
- (id) initWithType:(int)num eyeSide:(EyeSide)eyes type:(PointType)type imageSide:(ImageSide)image;
@end
With this implementation:
@implementation Action
@synthesize imageSide;
@synthesize eyeSide;
@synthesize pointType;
@synthesize actionId;
- (id) initWithType:(int)num eyeSide:(EyeSide)eyes type:(PointType)type imageSide:(ImageSide)image {
// Call superclass's initializer
self = [super init];
if( !self ) return nil;
actionId = num;
imageSide = image;
eyeSide = eyes;
pointType = type;
return self;
}
@end
And in my ViewController, I try to add it as a key to a NSMutableDictionary object, like this:
Action* currentAction = [[Action alloc] initWithType:0 eyeSide:right type:eye imageSide:top];
pointsDict = [[NSMutableDictionary alloc] initWithCapacity:20];
[pointsDict setObject:[NSValue valueWithCGPoint:CGPointMake(touchCoordinates.x, touchCoordinates.y)] forKey:currentAction];
However, I get this error, when setObject is called:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Action copyWithZone:]: unrecognized selector sent to instance
I went through some answers in SO related to this error, but no one seems to solve this problem, and as I am new to iOS development I’m quite puzzled by this.
You declare your
Actionclass to conform to theNSCopyingprotocol.So you need to implement
-(id)copyWithZone:(NSZone *)zonefor that class.