常用的宏,判断版本号,升序降序

常用的宏
///颜色转换 IOS中十六进制的颜色转换为UIColor
[Utility colorWithHexString:@"#f3f3f5”]

//自适应label高/宽 都行
#define CJTSIZE(_size, _string_,_font_) [_string_ boundingRectWithSize:_size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:_font_]} context:nil].size;

//4.获取当前ios系统版本号
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]

/**  获取当前app版本号 */
#define APP_VER        [[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"]

/**  获取当前app名字 */
#define APP_NAME [[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleDisplayName"]


#define IS_IOS7_LATER   ([UIDevice currentDevice].systemVersion.floatValue > 6.99)

// DLog
#ifdef  DEBUG
#define DLog(fmt,...) {NSLog((@
"%s [Line:%d]" 
fmt),__PRETTY_FUNCTION__,__LINE__,##__VA_ARGS__);}
#else
#define DLog(…)
#endif

//打印
#ifdef  DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"[%s:%d行] %s\n"
,[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif


//拿到当前window
UIWindow * window = [UIApplication sharedApplication].keyWindow; 

判断是否有这个宏 (Hong)
#ifdef Hong

#else

#endif

////
#if  Hong == 0
            
#else
            
#endif


枚举
//第一种写法
typedef enum{
    book,
    PC,
    Tel
}Types;
//第二种写法
typedef NS_OPTIONS (NSInteger, RecogResultType) {
    kResultTypeFront = 1,
    kResultTypeBack = 2,
    kResultTypeNameAndNumOnly = 3,
    kResultTypeUICustom = 4,
    kResultTypeScanFrontAndBack = 5,
};

//第三种
typedef NS_ENUM(NSUInteger, ZOCMachineState) {
    ZOCMachineStateNone,
    ZOCMachineStateIdle,
    ZOCMachineStateRunning,
    ZOCMachineStatePaused
};

升序降序
NSString *num1 = @"5.2.0";//APP版本
    NSString *num2 = @"5.3.0";//请求接口版本
    
    if ([num1 compare:num2 options:NSNumericSearch] == NSOrderedDescending)
    {
        NSLog(@"%@ 降序",num1);
    }else if ([num1 compare:num2 options:NSNumericSearch] == NSOrderedSame){
        NSLog(@"%@ 相等",num2);
    }else if ([num1 compare:num2 options:NSNumericSearch] == NSOrderedAscending){
        NSLog(@"%@ 升序",num2);
    }

你可能感兴趣的:(常用的宏,判断版本号,升序降序)