http://www.reibang.com/p/35df1ba1f107
OBJC_EXPORT void objc_setAssociatedObject(id object, const void *key, id value, objc_AssociationPolicy policy)
__OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_1);OBJC_EXPORT id objc_getAssociatedObject(id object, const void *key)
__OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_1);簡單的說:objc_setAssociatedObject是為對象動態(tài)添加屬性和值,objc_getAssociatedObject是動態(tài)獲得對象的屬性值。
objc_setAssociatedObject(id object, const void *key, id value, objc_AssociationPolicy policy)相當于動態(tài)添加屬性
object.key = valueobjc_getAssociatedObject(id object, const void *key)相當于
值 = object.key