使用多个目标进行 appdelegate 访问的宏
我正在阅读一篇关于使用宏的简写来访问应用程序委托的文章
[的简写] [UIApplication共享应用程序]委托]?。
所提供问题的解决方案是在应用程序委托标头中定义以下宏。
#define AppDelegate (YourAppDelegate *)[[UIApplication sharedApplication] delegate]
我的问题是,对于一个具有多个目标的项目,我该如何做到这一点,因为每个目标的应用程序委托名称都不同?
I was reading a post on accessing the app delegate using shorthand with a macro here
Short hand for [[UIApplication sharedApplication] delegate]?.
The solution to the problem provided was to define the following macro in the app delegate header.
#define AppDelegate (YourAppDelegate *)[[UIApplication sharedApplication] delegate]
My question is how can I do this with a project that has multiple targets seeing as the appdelegate name would be different for each one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
#define 宏只是预处理器中的字符串替换工具,因此我认为除了定义另一个具有每个目标的应用程序委托名称的宏之外,您无能为力。
通过输入缩写应用程序委托所节省的时间不会太多,而且在我看来可能不值得花时间这样做。
我将进一步编辑说,如果您对应用程序委托进行了足够的引用来证明缩写的合理性,我认为您需要将一些代码从 appDelegate 移出到更好的分解(可能是单例)类中。我的2分钱。
T he #define macro is just a string substitution facility in the pre-processor, so I don't think there is much you can do short of defining another macro that has the name for each target's app delegate.
The savings in typing to abbreviate the app delegate is not going to be very much, and imo probably not worth the time to do it.
And I will editorialize further to say that if you're making enough references to your app delegate to justify abbreviating, I think you need to move some code out of the appDelegate into better factored (possibly singleton) classes. My 2 cents.