美文网首页
iOS开发常用宏(2)

iOS开发常用宏(2)

作者: 高产的白猫 | 来源:发表于2016-11-04 14:11 被阅读0次

1.判断横竖屏

#define IsPortrait ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)

2.截取系统时间戳

#define getCurentTime [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]]

3.是否高清屏

#define isRetina ([[UIScreen mainScreen] scale]== 2 ? YES : NO)

4.当前系统设置国家的country iso code

#define countryISO  [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode]

5.当前系统设置语言的 iso code

#define languageISO [[NSLocale currentLocale] objectForKey: NSLocaleLanguageCode]

6.单例

#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \\static classname *shared##classname = nil; \\+ (classname *)shared##classname \{ \@synchronized(self) \{ \if (shared##classname == nil) \{ \shared##classname = [[self alloc] init]; \} \} \\return shared##classname; \} \\+ (id)allocWithZone:(NSZone *)zone \{ \@synchronized(self) \{ \if (shared##classname == nil) \{ \shared##classname = [super allocWithZone:zone]; \return shared##classname; \} \

7.内存方面宏

//使用ARC和不使用ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif
#pragma mark - common functions
#define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }
//释放一个对象
#define SAFE_DELETE(P) if(P) { [P release], P = nil; }
#define SAFE_RELEASE(x) [x release];x=nil

相关文章

  • iOS开发中常用的宏

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

  • iOS开发常用宏(2)

    1.判断横竖屏 2.截取系统时间戳 3.是否高清屏 4.当前系统设置国家的country iso code 5.当...

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

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

  • iOS 常用宏定义

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

  • 开发常用宏 - iOS

    开发中很多常用的方法会在很多地方被多次使用到,因此为了提升开发效率,特此将其配置为宏,从而使用起来更加得心应手,以...

  • iOS开发常用宏

    Debug与Release 自定义NSLog 屏幕宽度 颜色设置 沙盒路径

  • iOS开发常用宏

    设备 系统 设置Debug模式下打印log,release模式下不打印 颜色 字体大小(常规/粗体) 常用方法 单例

  • ios开发常用宏

    /** 屏幕宽度 */ #define eDeviceWidth [UIScreen mainScreen].bo...

  • iOS 开发常用宏

    引子: 今天一个前辈解决了我纠结了很久的问题,具体点说就是怎么在cell里面获取父视图的navigationCon...

  • iOS开发常用宏

    //字符串是否为空#define kStringIsEmpty(str) ([str isKindOfClass:...

网友评论

      本文标题:iOS开发常用宏(2)

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