美文网首页
OC观察者模式之Notification

OC观察者模式之Notification

作者: 芝麻酱的简书 | 来源:发表于2019-01-15 15:47 被阅读2次

通知Notification:

  • 通知是使用观察者模式这一设计模式来实现的用于跨层传递消息的机制
  • 传递方式为1对多

如何实现通知机制:

通知实现机制.png

通知中心NSNotificationCenter内部维护了一个map表(字典),字典中key值是notificationName,value是添加的observers数组列表。
数组列表的每一个成员包含通知接受观察者和该管观察者的回调方法等数据,可以用字典存储。

数据结构伪代码:

struct observer {
   notificationName,
   method,
   参数,
}

@{notificationName : 
                    @[observer1,
                      observer2,
                      observer3,
                         ...   ]
  }

相关文章

网友评论

      本文标题:OC观察者模式之Notification

      本文链接:https://www.haomeiwen.com/subject/gbeydqtx.html