美文网首页
iOS开发中常用的宏

iOS开发中常用的宏

作者: 小荣袁 | 来源:发表于2015-12-31 10:14 被阅读53次

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()

相关文章

  • iOS开发中常用的宏

    以下为iOS开发中常用宏: 引用:ios开发常用的宏,大家一起来收集 参考:ios开发常用的宏,大家一起来收集~

  • iOS 开发小经验

    iOS 开发中你是否遇到这些经验问题(一)iOS 开发中你是否遇到这些经验问题(二)iOS 日常工作之常用宏定义大全

  • iOS开发中常用到的宏

    大家都是知道使用宏不仅方便,而且可以提高开发效率。下面总结了iOS开发过程中的一些常用宏。

  • iOS开发常用的工具类和宏定义

    iOS开发常用的工具类和宏定义 开发总结的工具类和宏 https://github.com/xiaoChen66...

  • iOS 常用宏定义

    iOS 开发中使用一些常用宏定义可以大大提高开发效率,提高代码的重用性.以下是一些常用的宏定义: 像这些宏定义,在...

  • iOS 开发常用宏

    大家都是知道使用宏不仅方便,而且可以提高开发效率。下面总结了iOS开发过程中的一些常用宏,会持续的往里面添加。 /...

  • iOS 开发中 runtime 常用的几种方法

    iOS 开发中 runtime 常用的几种方法 iOS 开发中 runtime 常用的几种方法

  • iOS开发常用宏,持续更新中

    大家都是知道使用宏不仅方便,而且可以提高开发效率。下面总结了iOS开发过程中的一些常用宏,会持续的往里面添加。 持...

  • IOS开发中 常用的宏定义

    #ifndef iOS_Constants_h #define iOS_Constants_h /* ******...

  • iOS常用宏 定义

    iOS开发过程中,使用的一些常用宏定义 字符串是否为空#define kStringIsEmpty(str) ([...

网友评论

      本文标题:iOS开发中常用的宏

      本文链接:https://www.haomeiwen.com/subject/uagihttx.html