蘋果官方文檔()如下: PRoperty Type String You can use the property_getAttributes function to discover the name, the @encode type string of a property, and other attributes of the property. The string starts with a T followed by the @encode type and a comma, and finishes with a V followed by the name of the backing instance variable. Between these, the attributes are specified by the following descriptors, separated by commas:
RThe property is read-only (readonly).(只讀屬性)CThe property is a copy of the value last assigned (copy).(復(fù)制屬性)&The property is a reference to the value last assigned (retain).(持有屬性)NThe property is non-atomic (nonatomic).(非原子性的,釋義為不是線程安全的。atomic是iOS使用的一種線程保護(hù)技術(shù),大意是一個(gè)進(jìn)程讀寫字段時(shí),防止數(shù)據(jù)錯(cuò)誤,另一個(gè)進(jìn)程不允許訪問(wèn)。而這種機(jī)制是耗費(fèi)系統(tǒng)資源的,所以如果沒(méi)有使用多線程間的通訊編程,那么nonatomic是一個(gè)非常好的選擇。)G<name>The property defines a custom getter selector name. The name follows the G (for example, GcustomGetter,).(用戶自定義的get方法名稱)S<name>The property defines a custom setter selector name. The name follows the S (for example, ScustomSetter:,).(用戶自定義的set方法名稱)DThe property is dynamic (@dynamic).(@dynamic告訴編譯器,屬性的setter與getter方法由用戶自己實(shí)現(xiàn),不自動(dòng)生成。)WThe property is a weak reference (__weak).(弱引用屬性)PThe property is eligible for garbage collection.(屬性的垃圾回收機(jī)制是合格的)t<encoding>Specifies the type using old-style encoding.(指定使用老式的編碼類型)示例屬性:
@property char charDefault;Tc,VcharDefault@property double doubleDefault;Td,VdoubleDefault@property enum FooManChu enumDefault;Ti,VenumDefault@property float floatDefault;Tf,VfloatDefault@property int intDefault;Ti,VintDefault@property long longDefault;Tl,VlongDefault@property short shortDefault;Ts,VshortDefault@property signed signedDefault;Ti,VsignedDefault@property struct YorkshireTeaStruct structDefault;T{YorkshireTeaStruct="pot"i"lady"c},VstructDefault@property YorkshireTeaStructType typedefDefault;T{YorkshireTeaStruct="pot"i"lady"c},VtypedefDefault@property union MoneyUnion unionDefault;T(MoneyUnion="alone"f"down"d),VunionDefault@property unsigned unsignedDefault;TI,VunsignedDefault@property int (*functionPointerDefault)(char *);T^?,VfunctionPointerDefault@property id idDefault;Note: the compiler warns: "no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed"T@,VidDefault@property int *intPointer;T^i,VintPointer@property void *voidPointerDefault;T^v,VvoidPointerDefault@property int intSynthEquals;In the implementation block:@synthesize intSynthEquals=_intSynthEquals;Ti,V_intSynthEquals@property(getter=intGetFoo, setter=intSetFoo:) int intSetterGetter;Ti,GintGetFoo,SintSetFoo:,VintSetterGetter@property(readonly) int intReadonly;Ti,R,VintReadonly@property(getter=isIntReadOnlyGetter, readonly) int intReadonlyGetter;Ti,R,GisIntReadOnlyGetter@property(readwrite) int intReadwrite;Ti,VintReadwrite@property(assign) int intAssign;Ti,VintAssign@property(retain) id idRetain;T@,&,VidRetain@property(copy) id idCopy;T@,C,VidCopy@property(nonatomic) int intNonatomic;Ti,VintNonatomic@property(nonatomic, readonly, copy) id idReadonlyCopyNonatomic;T@,R,C,VidReadonlyCopyNonatomic@property(nonatomic, readonly, retain) id idReadonlyRetainNonatomic;T@,R,&,VidReadonlyRetainNonatomic(附上鏈接https://developer.apple.com/library/prerelease/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html#//apple_ref/doc/uid/TP40008048-CH101-SW1)
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注