iT邦幫忙

0

iOS APP 開發 OC 第八天,@synthesize

tags: OC 30 day

作用

自動生成getter,setter方法的實現,所以應該寫在類的實現當中。

語法。

@synthesize @property
@interface Person :NSObject
{
int_age;
}
@property int age;
@end
---------------
@implmentation Person

@sythesize age
@end

@sythesize做了什麼?

  1. 生成一個私有的屬性,屬性的類型和@synthesize對應的@property類形一致,屬性的名字和@synthesize對應的@property名字一致。
  2. 自動生成setter方法的實現。實現方式:將參數直接賦值給自動生成的私有屬性。並且沒有做任何的邏輯驗證。
  3. 自動生成getter方法的實現。實現方式:將生成的私有屬性值返回。

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
ytyubox
iT邦新手 5 級 ‧ 2020-12-30 18:28:43
Alvin iT邦新手 4 級 ‧ 2021-08-20 22:37:14 檢舉

因為 self.something 會進入到setter裡面,如果在setter裡面引用會造成死循環,不知道這樣的解釋正不正確?

我要留言

立即登入留言