How do I cleanly override a property setter?

If I want to define a custom UIView subclass that does something when its bounds are set, how do I override the setter? Overriding setBounds seems dangerous since, if I understand correctly, the getter and setter names are not part of the public interface and could change anytime.

Of course, I use class_copyPropertyList to query the runtime for a list of properties defined in the class, then query it for the setter's name, and finally use class_addMethod to add the method, after first getting a reference to the earlier method to use for calling the original version.

All this seems hacky. Is there a clean way to do what I want, which is guaranteed to not break on future OS versions? Thanks.

6
задан Vaddadi Kartick 21 March 2011 в 15:24
поделиться