我在实现一个简单的超/子类方案时遇到了一些麻烦。我在超类中声明了一个 NSMutableDictionary,并试图在子类中访问它,但它只返回 null。任何帮助,将不胜感激。
@interface RootModel : NSObject <Updatable, TouchDelegate>
@property (nonatomic) NSMutableDictionary *gameValues;
@end
@interface SubclassModel : RootModel
@end
@implementation RootModel
- (id)initWithController:(id)controller {
if ((self = [super init])) {
_controller = controller;
_gameValues = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:300.0f], KEY_JUMP_VELOCITY,
[NSNumber numberWithFloat:49.47f], KEY_GRAVITY,
[NSNumber numberWithFloat:0.25f], KEY_JUMP_TIME_LIMIT,
nil];
NSLog(@"%@", _gameValues);
}
return self;
}
@implementation SubclassModel
- (id)init{
if ((self = [super init])) {
// This NSLog prints "(null)" if using super.gameValues or self.gameValues, why?
NSLog(@"subclass: %@", super.gameValues);
}
return self;
}
@end
我究竟做错了什么?