如何监控objective-c方法返回值的变化
我在我的应用程序中使用 Sparkle http://sparkle-project.org/ 框架进行自动更新。我有一个启用/禁用自动更新下载的 UI 项目,但我既不能使用 Sparkle 文档中所述的 Interface Builder 绑定,也不能使用 KVO,因为没有用于自动更新下载的属性 - 只有 getter 和 setter 方法。我可以挂钩 setter 方法,并在该选项通过 Sparkle 的界面交互发生更改时调用回调吗?
在这种情况下我能做什么?
谢谢。
I'm using Sparkle http://sparkle-project.org/ framework for autoupdates in my application. I have a UI item which enables/disables automatic updates downloads, but I can use neither Interface Builder bindings as stated in documentation for Sparkle, nor KVO, because there is no property for automatic updates download - only getter and setter methods. Can I hook the setter method and have a callback invoked when this option changes through Sparkle's interface interaction.
What can I do in this situation?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果存在 getter 和 setter 方法,则隐含地存在一个属性,即使未声明该属性。您可以将 KVO 与它一起使用。事实上,多年来,这是实现 KVO 的唯一方法;没有明确的属性。 Cocoa 将任何带有适当命名的 getter 和 setter 的东西视为属性。
绑定使用相同的机制,因此您也应该能够使用绑定。不要因为没有申报财产而吓倒您。
If there are getter and setter methods, then there is implicitly a property, even if one is not declared. You can use KVO with it just fine. In fact, for many years, this was the only way to do KVO; there were no explicit properties. Cocoa treats anything with an appropriately named getter and setter as a property.
Bindings use the same mechanism, so you should be able to use bindings as well. Don't let the lack of a declared property scare you off.
为什么需要监控这些变化?我所知道的大多数应用程序仅在启动时检查更新,而不是在运行时检查更新。因此,您可以检查并更新或继续应用程序。
如果没有其他方法,计时器(NSTimer)将始终定期检查事物。
Why do you need to monitor these changes? The most application I know check for updates on startup only and not during runtime. So you would check and update or just continue with the application.
If there is no other way a timer (NSTimer) will always work to check things periodically.