我们可以通过这些方式使用AppDelegate的对象说...
1)
AppDelegate *app; // Globally declared
app = (AppDelegate*)[[UIApplication sharedApplication] delegate]; //Use this any where in app
2)
#define APP_DELEGATE ((AppDelegate*)[[UIApplication sharedApplication] delegate])
[APP_DELEGATE.navigationController ...]; //use macro any where in app
我想知道哪种方式在性能和处理速度方面更好?
答案 0 :(得分:2)
不要以为它会改变性能。它比其他任何东西都更实用。
答案 1 :(得分:2)
这两种方法都不会影响应用程序的性能。首先写清楚,可读性和良好的结构。
不要通过查看使用的方法调用数来尝试进行“性能增强”。方法调用实际上是免费的,除非你做了数百万次。
如果您经常与来自各地的应用代表交谈以担心访问速度,那么您在设计和实施应用时就犯了一个可怕的错误。
“通常足以担心访问的速度”我的意思是仪器(你正在使用仪器,对吗?你不能担心或改善你的应用程序的性能而不使用它)告诉你,获取参考app delegate是您当前的性能瓶颈。