简介
项目开发中经常会申明变量保存相关相关值,但是对于功能太多的类中申明过多的变量看着就非常的繁琐,尤其是使用动态语言如javaScript 写过功能的都知道,动态语言可以动态的在一个对象上添加新的属性和值,这将是非常有诱惑力的功能,而且objective-c 的动态特性是非常强大的
oc 关联值
/**
* Sets an associated value for a given object using a given key and association policy.
*
* @param object The source object for the association.
* @param key The key for the association.
* @param value The value to associate with the key key for object. Pass nil to clear an existing association.
* @param policy The policy for the association. For possible values, see “Associative Object Behaviors.”
*
* @see objc_setAssociatedObject
* @see objc_removeAssociatedObjects
*/
objc_setAssociatedObject(id _Nonnull object, const void * _Nonnull key, id _Nullable value, objc_AssociationPolicy policy)
/**
* Returns the value associated with a given object for a given key.
*
* @par