インスタンス変数として3つの列挙型を使用してカスタムクラスオブジェクトActionを作成しました。
@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
この実装では:
@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
そして、ViewControllerで、次のようにNSMutableDictionaryオブジェクトのキーとして追加しようとします。
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];
ただし、setObjectが呼び出されると、次のエラーが発生します。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Action copyWithZone:]: unrecognized selector sent to instance
私はこのエラーに関連してSOでいくつかの回答を調べましたが、誰もこの問題を解決していないようです。iOS開発に慣れていないので、これにはかなり戸惑っています。