开销NSNotifications [英] Overhead of NSNotifications

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

问题描述

我最近开始使用 NSNotification s:

[[NSNotificationCenter defaultCenter] postNotificationName: selector: object:]; ....

我认为这是一个用于在视图控制器之间通信的真棒概念。它似乎有点太容易使用 NSNotification s的应用程序中的所有通信。

I find it to be an awesome concept for communicating between view controllers. It almost seems a little too easy to use NSNotifications for all the communications in the app.

如果我在应用程序的大部分工作中使用 NSNotification

In the event that I use NSNotifications for most of the work in my app, what do you think would be the overhead for too many of them?

推荐答案

我似乎回忆起NSNotification相当耗费开销,所以使用很多的他们可能不会是最好的主意。相反,我会考虑采用委托协议。

I seem to recall reading that NSNotification is pretty overhead consuming, so using a lot of them probably wouldn't be the best idea. Instead, I'd look into adopting delegate protocols. You can easily create your own to tell your files what to do and when.

这个网站提供了一个非常类似于我用来学习如何创建代理的例子,寻找。我曾经一直使用NSNotifications,直到我了解了代理,并已将所有我的通知切换到代理方法

This site gives an example fairly similar to the one I used to learn how to create delegates and might be worth looking into. I used to use NSNotifications all the time until I learned about delegates and have since switched all my notifications over to delegate methods instead

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

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