Linked objects come in handy whenever you want to fake ivar in a class. They are very versatile since you can associate any object with this class.
However, you should use it wisely and only for minor things when subclasses seem cumbersome.
However, if your only requirement is to add an integer to all instances of UIView , tag is the way to go. This is already there and is ready for you to use, so there is no need to include corrections at runtime of the UIView .
If you want to tag your UIView with something larger than an integer, such as a shared object, you can define a category as shown below.
UIView + Tagging.h
@interface UIView (Tagging) @property (nonatomic, strong) id customTag; @end
UIView + Tagging.m
The trick using the property selector as a key was recently proposed by Erica Sadun in this post.
Gabriele Petronella Apr 15 '13 at 16:13 2013-04-15 16:13
source share