NSNotification如何运作 [英] How NSNotification works

查看:130
本文介绍了NSNotification如何运作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解通知,海报和观察者的内容。

I understand what in Notification, poster and observer.

但是我无法理解我们的应用程序或操作系统如何理解并将标志/通知发送给观察者类?

But I am quite unable to understand how our app or OS understands and sends the flag/notification to the observer-class?

这背后的机制是什么?

您的回答和帮助将会受到很多赞赏。

Your answer and help will be appreciated a lot.

谢谢

ID。

推荐答案

想象一下通知中心一个字典,其中包含通知名称的键和观察者列表的值(及其指定的操作方法)。发布通知时,将获取并迭代该通知名称的观察者列表。每个观察者都使用通知信息调用其动作方法。

Imagine the Notification Center as a dictionary which has keys of the notification names and values of the list of observers (and their specified action methods). When a notification is posted, the list of observers for that notification name is obtained and iterated. Each observer has its action method called with the notification information.

此外,在迭代期间还有一个检查以确定观察者是否对通知对象感兴趣(基于关于添加观察者时提供的参数。)

Also, during the iteration there is a check to determine if the notification object is of interest to the observer (based on the parameters supplied when the observer was added).

通知过程是在发布通知的线程上进行的。

The notification process is carried out on the thread from which the notification was posted.

不要考虑依赖任何与添加观察者的方式和时间相关的隐含订单。

Don't think about trying to rely on any implied order related to how and when the observers were added.

这篇关于NSNotification如何运作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆