[[UIApplication sharedApplication] delegate]的短手] [英] Short hand for [[UIApplication sharedApplication] delegate]?

查看:96
本文介绍了[[UIApplication sharedApplication] delegate]的短手]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AppDelegate中存储全局变量,并通过以下方式访问它们:

  AppDelegate * d = [[UIApplication sharedApplication] delegate] ; 
d.someString = ...

什么是推荐的方法来保存一些打字等我不需要一次又一次的 AppDelegate * d = [[UIApplication sharedApplication] delegate]; 谢谢!

解决方案

As Shaggy Frog 说,在YourAppDelegate.h文件中定义一个宏,例如:

  #define AppDelegate(YourAppDelegate *)[[UIApplication sharedApplication] delegate] 

然后,您可以在代码中获取应用程序委托:

  [AppDelegate ......]; 


I stored global variables in my AppDelegate and access them by:

AppDelegate *d = [[UIApplication sharedApplication] delegate];
d.someString = ...

What's the recommend way to save some typing and so I don't need to AppDelegate *d = [[UIApplication sharedApplication] delegate]; again and again? Thanks!

解决方案

As Shaggy Frog said, define a macro in your YourAppDelegate.h file, an example like this:

#define AppDelegate (YourAppDelegate *)[[UIApplication sharedApplication] delegate]

Then you can get the app delegate in your code like this:

[AppDelegate ......];

这篇关于[[UIApplication sharedApplication] delegate]的短手]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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