iOS delegate、NSNotification效率比较
来源:互联网 发布:淘宝耐克双肩包 编辑:程序博客网 时间:2024/05/21 04:17
//联系人:石虎 QQ: 1224614774 昵称:嗡嘛呢叭咪哄
一、delegate的效率肯定比NSNotification高.
delegate方法比notification更加直接,最典型的特征是,delegate方法往往需要关注返回值,也就是delegate方法的结果。
比如-windowShouldClose: 需要关心返回的是yes还是no。所以delegate方法往往包含 should这个很传神的词。也就是好比你做我的delegate,我会问你我想关闭窗口你愿意吗?你需要给我一个答案,我根据你的答案来决定如何做下一步。相反的,notification最大的特色就是不关心接受者的态度,我只管把通告放出来,你接受不接受就是你的事情,同时我也不关心结果。
所以notification往往用did这个词汇,比如NSWindowDidResizeNotification,那么NSWindow对象放出这个notification后就什么都不管了也不会等待接受者的反应。
二、KVO和NSNotification的区别:
1)和delegate一样,KVO和NSNotification的作用也是类与类之间的通信,与delegate不同的是:这两个都是负责发出通知,剩下的事情就不管了,所以没有返回值;
2)delegate只是一对一,而这两个可以一对多。这两者也有各自的特点。
谢谢!!!
阅读全文
0 0
- iOS delegate、NSNotification效率比较
- delegate、NSNotification、block三者的比较
- iOS之KVC、KVO、Delegate、NSNotification区别
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault)
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault)
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault)
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- 数据结构-实现俩链表(int)拼接后还是有序的
- 为国庆献礼:无人智能系统,守护祖国海空长城
- 16杭州ccpc Equation HDU
- Set集合及其实现类
- 选择排序
- iOS delegate、NSNotification效率比较
- BZOJ 2648 SJY摆棋子 KDtree
- UVA-10587 Mayor's Posters verZGC-PJ
- HTML 逆序输出 输出引号
- 文章标题
- 顺序表的基本操作
- Docker 镜像的存储机制
- SonarQube插件开发自定义规则(1)简易demo
- POJ