我今天發現了這個,只是想驗證我對發生了什麼事的理解。 「prefixName」是一個使用getter方法直接傳回值的只讀屬性,沒有iVar將結果存儲在PR_ViewController對象上。此外,如果該屬性不是隻讀添加一個setter仍然不會工作,因爲沒有iVar設置。沒有iVar和getter方法的屬性?
- 創建:[甲基] prefixName
相比之下 「characterName」 適用於一個屬性通常的方式,加入了吸氣劑,一個設置器和一個IVAR。
- 創建:[甲基] characterName
- 創建:[甲基] setCharacterName
- 創建:[IVAR] characterName
。
@interface PR_ViewController : UIViewController
@property (nonatomic, readonly) NSString *prefixName;
@property (nonatomic, retain) NSString *characterName;
。
@implementation PR_ViewController
@synthesize characterName;
- (NSString *)prefixName {
return @"FRED";
}
不要重複您的問題。請關閉其中一個。 – Ilanchezhian 2012-01-09 13:04:33
你正確地理解它。 – 2012-01-09 13:04:37
[Property with no iVar and getter method?]可能重複?(http://stackoverflow.com/questions/8788773/property-with-no-ivar-and-getter-method) – rckoenes 2012-01-09 13:34:00