常用的宏,判斷版本號,升序降序

常用的宏
///顏色轉換 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);
    }
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容