Objective-C Associated Objects
suggest changeIntroduction
First introduced in iOS 3.1 as part of the Objective-C runtime, associated objects provide a way to add storage to an existing object without subclassing.
This means you can attach any object to any other object without subclassing.
Syntax
- void objc_setAssociatedObject(id object, void *key, id value, objc_AssociationPolicy policy)
- id objc_getAssociatedObject(id object, void *key)
- void objc_removeAssociatedObjects(id object)
Parameters
| Param | Details |
|---|---|
| object | The existing object you want to modify |
| key | A pointer with a stable address. A common choice is the address of a static variable. |
| value | The object you want to add |
| policy | The memory policy for this new value: retain, assign, or copy, as with any other property |
Remarks
More details here:
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents