在重用默认实现的同时为 @property 实现自定义设置器
我想在每次设置属性时向委托报告。
我想到的方法是简单地在属性的设置期间将消息添加到委托中。
现在,显而易见的方法是简单地编写设置属性的通用逻辑,并在最后添加委托调用 - 但这感觉很愚蠢。
我希望能够在开始时调用某种 [super setProperty],并在最后添加我自己的逻辑。 (但 super 当然没有意义)
这样,如果我将属性类型从“分配”更改为“保留”,我就不需要更改设置器代码。
有什么办法吗?如果没有 - 除了明显的方式之外还有什么更好的建议吗?
I want to report to delegate each time I set a property.
The way I thought of doing it is to simply add the message to delegate during the setter of the property.
Now, the obvious way would be to simply write the common logic of setting a property and simply add the delegate call in the end - but this feels stupid.
I would prefer to be able to call some kind of [super setProperty] in the beginning, and only add my own logic at the end. (but super doesn't make sense of course)
This way if I change the property type from 'assign' to 'retain' I wouldn't need to change the setter code.
Any way of doing that? If not - any better suggestions over the obvious way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
键值观察
你的“委托”对象可以注册以在对象的属性发生更改时接收通知。合成的 setter 符合 KVO 标准。
Key value observation
Your 'delegate' object can register to receive notification when a property on your object changes. The synthesised setters are KVO compliant.
这是一个简单的键值观察案例,我必须承认我自己还没有尝试过。您可以参考文档..或查看此 http://theocacao.com/document.page/161
This is a simple case of Key-value-observation which I must admit that I haven't tried myself. You can refer the docs.. or see this http://theocacao.com/document.page/161