博客
关于我
PCH文件设置以及常用的宏
阅读量:596 次
发布时间:2019-03-11

本文共 4811 字,大约阅读时间需要 16 分钟。

PCH ??? Xcode ????????

PCH ????? Pre-Compiled Header ???? Xcode ??????????????????????????????????????????????

1. PCH ????

PCH ???????????????????????????? Xcode 6 ???????????????????? PCH ?????????

2. ???? PCH ??

? Xcode ????? PCH ????????

  • ?? Xcode ????????????Supporting Files?????
  • ????????????
  • ?????? "Other" -> "PCH File"?
  • ?????? PCH ?????? .pch ???
  • ?????????? Xcode ????????
  • ? PCH ?????????????????????

    3. ?????

    ? PCH ??????????????? .m ???????????????????

    3.1 ???????

    #define SCREEN_WIDTH    [UIScreen mainScreen].bounds.size.width
    #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

    ????????????????

    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
    #define SCREEN_WIDTH ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.width / [UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.width)
    #define SCREEN_HEIGHT ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.height / [UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.height)
    #define SCREEN_SIZE ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? CGSizeMake([UIScreen mainScreen].nativeBounds.size.width / [UIScreen mainScreen].nativeScale, [UIScreen mainScreen].nativeBounds.size.height / [UIScreen mainScreen].nativeScale) : [UIScreen mainScreen].bounds.size)
    #else
    #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
    #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
    #define SCREEN_SIZE [UIScreen mainScreen].bounds.size
    #endif

    3.2 ??????

    #define WMNotificationCenter [NSNotificationCenter defaultCenter]

    3.3 ??????

    #define WMRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]

    3.4 ?? RGB/RGBA ??

    #define WMRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
    #define WMRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]
    #define WMClearColor [UIColor clearColor]

    3.5 ?????

    #ifdef DEBUG
    #define LRLog(...) NSLog(@"%s ?%d? \n %@", __func__, __LINE__, [NSString stringWithFormat:__VA_ARGS__])
    #else
    #define LRLog(...)
    #endif

    3.6 ???????

    #define WMWeakSelf(type)  __weak typeof(type) weak##type = type;
    #define WMStrongSelf(type) __strong typeof(type) type = weak##type;

    3.7 ???????

    #define WMViewBorderRadius(View, Radius, Width, Color) \
    [View.layer setCornerRadius:Radius]; \
    [View.layer setMasksToBounds:YES]; \
    [View.layer setBorderWidth:Width]; \
    [View.layer setBorderColor:[Color CGColor]]

    3.8 ???????

    #define WMDegreesToRadian(x) (M_PI * x / 180.0)
    #define WMRadianToDegrees(radian) (radian * 180.0 / M_PI)

    3.9 ??????/????

    // ?????
    #define kGetViewWidth(view) view.frame.size.width
    #define kGetViewHeight(view) view.frame.size.height
    #define kGetViewX(view) view.frame.origin.x
    #define kGetViewY(view) view.frame.origin.y
    #define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@", imageName]]

    3.10 ARC ? MRC ??

    #if __has_feature(objc_arc)
    // ARC
    #else
    // MRC
    #endif

    3.11 ???????????

    // ????? iPhone
    #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    #define IS_IPHONE ([[UIDevice currentDevice] model] isEqualToString:@"iPhone")
    // ????? iPad
    #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    #define IS_IPAD ([[UIDevice currentDevice] model] isEqualToString:@"iPad")
    // ????? iPod
    #define IS_IPOD ([[UIDevice currentDevice] model] isEqualToString:@"iPod touch")
    // ????? iPhone 5SE
    #define iPhone5SE [[UIScreen mainScreen] bounds].size.width == 320.0f && [[UIScreen mainScreen] bounds].size.height == 568.0f
    // ????? iPhone 6/6s
    #define iPhone6_6s [[UIScreen mainScreen] bounds].size.width == 375.0f && [[UIScreen mainScreen] bounds].size.height == 667.0f
    // ????? iPhone 6Plus/6sPlus
    #define iPhone6Plus_6sPlus [[UIScreen mainScreen] bounds].size.width == 414.0f && [[UIScreen mainScreen] bounds].size.height == 736.0f
    // ??????
    #define IOS_SYSTEM_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
    #define IOS_SYSTEM_STRING [[UIDevice currentDevice] systemVersion]
    // ?? iOS 8 ?????
    #define IOS_VERSION_8_OR_LATER (([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) ? (YES) : (NO))

    3.12 ????????

    // ????? iOS ??
    #if TARGET_OS_IPHONE
    # endif
    // ????????
    #if (TARGET_IPHONE_SIMULATOR)
    # else
    # endif

    3.13 ??????

    // ?? temp ??
    #define kPathTemp NSTemporaryDirectory()
    // ???? Document ??
    #define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
    // ???? Cache ??
    #define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

    ????????????????????????????

    转载地址:http://lzxtz.baihongyu.com/

    你可能感兴趣的文章
    netty底层源码探究:启动流程;EventLoop中的selector、线程、任务队列;监听处理accept、read事件流程;
    查看>>
    Netty核心模块组件
    查看>>
    Netty框架的服务端开发中创建EventLoopGroup对象时线程数量源码解析
    查看>>
    Netty源码—2.Reactor线程模型一
    查看>>
    Netty源码—4.客户端接入流程一
    查看>>
    Netty源码—4.客户端接入流程二
    查看>>
    Netty源码—5.Pipeline和Handler一
    查看>>
    Netty源码—6.ByteBuf原理二
    查看>>
    Netty源码—7.ByteBuf原理三
    查看>>
    Netty源码—7.ByteBuf原理四
    查看>>
    Netty源码—8.编解码原理二
    查看>>
    Netty源码解读
    查看>>
    Netty的Socket编程详解-搭建服务端与客户端并进行数据传输
    查看>>
    Netty相关
    查看>>
    Network Dissection:Quantifying Interpretability of Deep Visual Representations(深层视觉表征的量化解释)
    查看>>
    Network Sniffer and Connection Analyzer
    查看>>
    NFS共享文件系统搭建
    查看>>
    ng 指令的自定义、使用
    查看>>
    nginx + etcd 动态负载均衡实践(二)—— 组件安装
    查看>>
    Nginx + uWSGI + Flask + Vhost
    查看>>