我在99%的项目中使用了我的DataManager单例类。而不是在每个类中导入它,我考虑只在pch文件中导入它,就像我对常量所做的那样。这样做有什么缺点吗?这被认为是不好的做法吗?
谢谢
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "Constants.h"
#import "DataManager.h"
#endif发布于 2013-07-16 05:43:53
对#导入XYZ.h的良好做法的评估将是,在项目的整个生命周期内,
NSTimeInterval saved = (time that would have been spent compiling XYZ.h plus every header it #imports in each file that included it every build);
NSTimeInterval wasted = (time spent recompiling files that do not include XYZ.h when XYZ.h changed);
if (saved > wasted) goodPractice = YES;所以任何system #import,很可能是你的库#import,都是很好的候选者。任何其他东西;好吧,如果95%的代码无论如何都是用那个特定的头重新编译的,那么把它放在那里是有意义的。
发布于 2013-07-15 16:35:10
如果头文件没有太多变化,那么在pch中包含一个导入并不是坏事(而且在大多数文件中都不使用导入时,这不是您的情况)。检查此问题的接受答案,并决定-
Is there a reason for which one should not add all the imports inside .pch file?
https://stackoverflow.com/questions/17649655
复制相似问题