iOS - AppDelegate 中的头文件太多?
我只是想知道将大量头文件导入 AppDelegate 是否被认为是不好的做法?
我的游戏有很多视图(在单独的 .xib 文件中),AppDelegate 在这些视图之间切换。目前,我正在 AppDelegate.h 文件中导入 16 个头文件,但有没有更好的方法来管理所有这些?我见过的大多数示例代码最多有 4 或 5 个头文件。
谢谢!
I was just wondering if it's considered bad practice to have a large number of header files imported into an AppDelegate?
My game has a lot of views (in separate .xib files) that the AppDelegate switches between. At the moment, I am importing 16 header files in my AppDelegate.h file, but is there a better way to manage all of this? Most sample code I've seen has a maximum of around 4 or 5 header files.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常更好的做法是在头文件中转发声明您的类,然后在实现文件中导入它们的头,例如:
这样做将有助于避免最终出现循环
#import
的情况参考。为了清楚起见,我还经常创建一个头文件,只是为了导入其他头文件,例如
#import "MyViews.h"
It's usually better practice to forward declare your classes in the header file, and then import their headers in your implementation file, for example:
Doing this will help to avoid situations where you will end up with circular
#import
references.I will also often create a header file simply for importing other header files for clarity, e.g.
#import "MyViews.h"
示例代码就是这样的——示例代码,通常旨在清楚地演示一个概念。如果您的应用程序执行不止一件相对简单的事情,则不要期望它看起来像示例代码。期望它看起来更像是几十个示例项目放在一起(尽管我不建议完全这样做!)。
Sample code is just that -- sample code, usually meant to clearly demonstrate a single concept. Don't expect your application to look like sample code if it does more than one single relatively simple thing. Expect it to look more like several dozen sample projects all put together (although I wouldn't advise doing exactly that!).