收到 NSNotification 的速度有多快?

发布于 2024-12-11 11:53:54 字数 250 浏览 4 评论 0原文

我有一个作为单例实现的控制器对象,它有一个可以随时驱逐对象的缓存。当对象即将被删除时,我想通知任何使用此控制器的类,以便它们能够做出适当的响应。我对这种行为的第一直觉是使用委托,因为它可以保证立即响应,但是因为控制器可以由许多不同的类访问,所以这并不适合。

通知是显而易见的选择,但是我想知道有关 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 NSNotifications. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流殇 2024-12-18 11:53:54

他们立即交付。但需要注意的一件事是,它们是在生成通知的线程上传递的,而不是在注册接收通知的线程上传递的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文