assign 使用簡單賦值語句為實(shí)例變量設(shè)置值
copy 使用copy方法設(shè)置實(shí)例變量的值
nonatomic
直接返回值。若沒有聲明該屬性,那么就是atomic屬性,擠兌實(shí)例變量的存儲是互斥鎖定的。在沒有垃圾回收的環(huán)境下,系統(tǒng)retain這個實(shí)例變量,并設(shè)置autorelease 然后才返回值
readonly 不能設(shè)置實(shí)例變量的值,編譯器不生成setter'方法
readwrite 可以獲取并設(shè)置實(shí)例變量的值。在實(shí)現(xiàn)類文件中,使用@synthesize,編譯器自動產(chǎn)生setter和getter方法
retain 在賦值的時候執(zhí)行retain(保持)操作
getter=name 取值方法使用name制定的名稱,而不是實(shí)例變量的名稱
setter=name 賦值方法使用name制定的名稱,而不是實(shí)例變量的名稱
這里的參數(shù)主要分為三類:
讀寫屬性: (readwrite/readonly)
setter語意:(assign/retain/copy)
原子性: (atomicity(nonatomic)
assign/retain/copy 決定了以何種方式對數(shù)據(jù)成員賦予新值
atomicity的默認(rèn)值是atomic,讀取函數(shù)為原子操作。
經(jīng)常用到的參數(shù)是 copy/reain/assign。
在其中選擇一個來確定屬性的setter如何處理這個屬性。很多Objective-C中的object最好使用用retain,一些特別的object(例如:string)使用copy。
assign關(guān)鍵字代表setter直接賦值,而不是復(fù)制或者保留它。這種機(jī)制非常適合一些基本類型,比如NSInteger和CGFloat,或者你并不直接擁有的類型,比如delegates。
readonly關(guān)鍵字代表setter不會被生成, 所以它不可以和 copy/retain/assign組合使用。
在實(shí)現(xiàn)里,只需要
@synthesize mainView;
@synthesize window;
就可代替 繁瑣的setter, getter方法, 這樣就 可讓編譯器自動生成讀寫函數(shù),定義了property, 使用者,可以 點(diǎn)號(.) 來存取屬性了。