美文网首页
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开发常用宏(2)

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