2009-01-09 64 views
2
-(NSDictionary *)properties; 
+(NSDictionary *)ClassProperties; 

现在,我该如何从子类调用ClassProperties?如何从类的实例调用方法?

-(NSDictionary *)properties { 
    return [? ClassProperties]; 
} 

的一点是,ClassProperties获取类属性的列表,所以我不能调用基类的定义。

回答

5

除了马克的响应线,你可以更普遍呼吁与

[[self class] ClassProperties] 

事实上,方法,如果你的基类和所有子类实现+ (NSDictionary *)ClassProperties,那么你的基类,能做到这一点

- (NSDictionary *)properties { 
    return [[self class] ClassProperties]; 
} 

然后您的任何子类都不需要知道- (NSDictionary *)properties。根据self是什么来调用正确的类方法。

1

您可以使用子类的类名称。