1.) 打开你的Xcode工程. 在Supporting Files目录下,选择 File > New > File > iOS > Other > PCH File 然后点击下一步;
2.) 给你的PCH文件起名字TestDemo-Prefix.pch. 例如你的项目工程名为TestDemo然而你的PCH 文件的名字应该为 TestDemo-Prefix.pch,然后创建;
4.) 找到 Project > Build Settings > 搜索 “Prefix Header“;
5.) “Apple LLVM 7.0 -Language″ 栏目中你将会看到 Prefix Header 关键字;
6.) 输入: $(SRCROOT)/YourProjectName/YourProject-Prefix.pch (如 TestDemo/TestDemo-Prefix.pch );
7.),将Precompile Prefix Header为YES,预编译后的pch文件会被缓存起来,可以提高编译速度。
//RGB颜色设置
#define RGBA(r, g, b, a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
//十六进制颜色设置
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
//屏幕的宽高
#define Screen_width [UIScreen mainScreen].bounds.size.width
#define Screen_height [UIScreen mainScreen].bounds.size.height
//获取系统版本
#define IOS_Version [[[UIDevice currentDevice] systemVersion] floatValue]
//NSUserDefaults 实例化
#define User_Default [NSUserDefaults standardUserDefaults]
//通知中心
#define NSNotCenter [NSNotificationCenter defaultCenter]
//打印
#ifdef DEBUG
#define DLog(fmt, ...) NSLog((@"<%s : %d> %s " fmt), [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__);
#else
#define DLog(...)
#endif
public let ScreenWidth: CGFloat = UIScreen.main.bounds.size.width
public let ScreenHeight: CGFloat = UIScreen.main.bounds.size.height
public let ScreenBounds: CGRect = UIScreen.main.bounds
//swift版
public func DLog<T>(message: T, file: String = #file, method: String = #function, line: Int = #line) {
#if DEBUG
print("<\((file as NSString).lastPathComponent) : \(line)>, \(method) \(message)")
#endif
}