2012-07-02 44 views
1

我在類中有一個常量,我通過#define HEIGHT 65定義了它我知道如何通過調用返回此方法的getter方法不變。我的意思是,我不想這樣做:使用屬性作爲常量而不調用返回常量的getter方法

#define HEIGHT 65 

. 
. 
. 

-(int)getHeight{ 
    return HEIGHT; 
} 

但問題是有定義常量@property並像其他properties通過instanceClass.HEIGHT得到它的方式。

任何想法?

回答

1

什麼:

@property (nonatomic, readonly) int height; 

,然後在實現文件:

@dynamic height; 

.... 

- (int)height { 
    return HEIGHT; 
} 
+0

你的意思是使用'#define'爲'HEIGHT'? –

+0

是的,我的意思是;我認爲這是最乾淨的解決方案,但是如果你喜歡,你可以'返回65;'... – sergio

+1

是@ @ dynamic'需要的;您似乎通過提供getter方法來滿足要求? – trojanfoe