iOS runtime 学习之类的属性动态获取(一)
2017-02-24 11:19
337 查看
苹果官方文档()如下:
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:
示例属性:
(附上链接https://developer.apple.com/library/prerelease/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html#//apple_ref/doc/uid/TP40008048-CH101-SW1)
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:
R The property is read-only (readonly).(只读属性) C The property is a copy of the value last assigned (copy).(复制属性) & The property is a reference to the value last assigned (retain).(持有属性) N The property is non-atomic (nonatomic).(非原子性的,释义为不是线程安全的。atomic是iOS使用的一种线程保护技术,大意是一个进程读写字段时,防止数据错误,另一个进程不允许访问。而这种机制是耗费系统资源的,所以如果没有使用多线程间的通讯编程,那么nonatomic是一个非常好的选择。) 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方法名称) D The property is dynamic (@dynamic).(@dynamic告诉编译器,属性的setter与getter方法由用户自己实现,不自动生成。) W The property is a weak reference (__weak).(弱引用属性) P The property is eligible for garbage collection.(属性的垃圾回收机制是合格的) 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)
相关文章推荐
- ios开发runtime学习四:动态添加属性
- objective-c运行时机制runtime,动态获取对象的属性和成员变量
- iOS开发------runtime关联对象(动态添加属性)
- jQuery基础学习(3)(获取标签属性,动态添加标签)
- XZ_iOS之Runtime使用运行时获取类的属性列表
- ios 通过runtime 获取属性列表并修改变量值
- iOS runtime 根据类名获取属性的类型和名称
- ios学习路线—Objective-C(Runtime成员变量与属性)
- iOS分类中通过runtime添加动态属性
- iOS分类中通过runtime添加动态属性
- ios runtime 获取 class 属性
- iOS学习笔记56(Runtime)-Objective-C Runtime 运行时之二:成员变量与属性
- iOS分类中通过runtime添加动态属性
- iOS运行时runtime获取私有属性和强制更改私有属性,以及获取私有方法
- ios专题 - objc runtime 动态增加属性
- 反射学习2-通过反射机制动态获取属性的值模拟Struts的自动赋值
- ios runtime 动态属性objc_setAssociatedObject和objc_getAssociatedObject
- Jquery学习之旅之动态设置css属性和获取css属性
- iOS的runtime获取类的属性的数据类型
- iOS Runtime 动态添加属性不能添加intrinsic类型