2009-01-09 68 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

您可以使用子類的類名稱。