简体   繁体   English

NSNotification收到的速度有多快?

[英]How quickly is an NSNotification received?

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. 通知是显而易见的选择,但是我想知道关于NSNotification传递的规则是什么。 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? 还是在收到通知之前不确定等待,以致无法保证交付速度?

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. 但是要注意的一件事是,它们是在生成通知的线程上传递的,而不是在已注册接收通知的线程上传递的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM