1.自定义NSLog
#ifdef DEBUG //开发阶段-DEBUG阶段:使用Log
#defineYYLog(...) NSLog(__VA_ARGS__)
#else // 发布阶段-上线阶段:移除Log
#define YYLog(...)
#endif
2.适配
#define YYIOS_VERSION[[[UIDevice currentDevice] systemVersion] floatValue]
#defineYYSCREEN_W [UIScreen mainScreen].bounds.size.width
#define YYSCREEN_H[UIScreen mainScreen].bounds.size.height
#define iOS7 ([[UIDevice currentDevice].systemVersiondoubleValue] >= 7.0)
#define iOS8 ([[UIDevicecurrentDevice].systemVersion doubleValue] >= 8.0)
#define iOS9 ([[UIDevicecurrentDevice].systemVersion doubleValue] >= 9.0)
#define YYiPhone4_OR_4s (YYSCREEN_H == 480)
#define YYiPhone5_OR_5c_OR_5s (YYSCREEN_H == 568)
#define YYiPhone6_OR_6s (YYSCREEN_H == 667)
#define YYiPhone6Plus_OR_6sPlus (YYSCREEN_H == 736)
#defineYYiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
3.弱引用
#define YYWeakSelf__weak typeof(self) weakSelf = self;
4.输出plist 文件到本机桌面
#define YYWriteToPlist(data,filename)
[data writeToFile:[NSString stringWithFormat:
@"/Users/YourName/Desktop/%@.plist", filename] atomically:YES];
5.颜色
// 随机色
#define YYRandomColor [UIColorcolorWithRed:
arc4random_uniform(255) / 255.0f
green:arc4random_uniform(255) / 255.0f
blue:arc4random_uniform(255) / 255.0f alpha:1.0f]
// ARGB
#define YYARGBColor(a, r, g,b) [UIColor colorWithRed:(r)/255.0f
green:(g)/255.0f blue:(b)/255.0f alpha:(a)/255.0f]
// RGB
#define YYColor(r, g, b) YYARGBColor(255, (r), (g), (b))
// 灰色
#define YYGrayColor(v)YYColor((v), (v), (v))
6.加载本地文件
#defineYYLoadImage(file,type)
[UIImage imageWithContentsOfFile:[[NSBundlemainBundle]pathForResource:file
ofType:type]]
#defineYYLoadArray(file,type)
[UIImage arrayWithContentsOfFile:[[NSBundlemainBundle]pathForResource:file
ofType:type]]
#defineYYLoadDict(file,type)
[UIImage dictionaryWithContentsOfFile:[[NSBundlemainBundle]pathForResource:file
ofType:type]]
7.多线程GCD
#define YYGlobalGCD(block)dispatch_async
(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#defineYYMainGCD(block) dispatch_async(dispatch_get_main_queue(),block)
8.数据存储
#defineYYUserDefaults [NSUserDefaults standardUserDefaults]
#defineYYCacheDir [NSSearchPathForDirectoriesInDomains
(NSCachesDirectory,NSUserDomainMask, YES) lastObject]
#defineYYDocumentDir [NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory,NSUserDomainMask, YES) lastObject]
#defineYYTempDir NSTemporaryDirectory()