收到 NSNotification 的速度有多快?
我有一个作为单例实现的控制器对象,它有一个可以随时驱逐对象的缓存。当对象即将被删除时,我想通知任何使用此控制器的类,以便它们能够做出适当的响应。我对这种行为的第一直觉是使用委托,因为它可以保证立即响应,但是因为控制器可以由许多不同的类访问,所以这并不适合。
通知是显而易见的选择,但是我想知道有关 NSNotification
的传递的规则是什么。它们是立即传递给代表的消息吗?或者在收到通知之前是否存在不确定的等待时间,从而无法保证交付速度?
I have a controller object implemented as a singleton, which has a cache that may evict objects at any time. I want to inform any classes that make use of this controller when an object is about to be removed so they can respond appropriately. My first instinct for this kind of behaviour was to use a delegate, as it can guarantee an immediate response, however because the controller can be accessed by a number of different classes this doesn't really fit.
Notifications are the obvious choice, however I would like to know what the rules are about the delivery of NSNotification
s. Are they delivered instantly, as in a message to a delegate? Or is there an indeterminate wait before a notification is received, such that no guarantee can be made as to the speed of delivery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
他们立即交付。但需要注意的一件事是,它们是在生成通知的线程上传递的,而不是在注册接收通知的线程上传递的。
They are delivered immediately. One thing to note though is that they are delivered on the thread that the notification was generated from, not the thread that it was registered to be received from.