iOS常用宏定义

字符串是否为空

#define kStringIsEmpty(str)  ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )

数组是否为空

#define kArrayIsEmpty(array)  ( [array isKindOfClass:[NSNull class]] || array == nil || array.count == 0)

字典是否为空

#define kDictIsEmpty(dic)  ([dic isKindOfClass:[NSNull class]] || dic == nil || dic.allKeys == 0)

APP版本号

#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

系统版本号

#define kSystemVersion [[UIDevice currentDevice] systemVersion]

判断是否为iPhone

#define kISiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

判断是否为iPad

#define kISiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

获取沙盒Document路径

#define kDocumentPath  [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

获取沙盒temp路径

#define kTempPath NSTemporaryDirectory()

获取沙盒Cache路径 

#define kCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

判断是真机还是模拟器

#if TARGET_OS_IPHONE

    //真机

#endif

#if TARGET_IPHONE_SIMULATOR

    //模拟器

#endif

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • iOS开发过程中,使用的一些常用宏定义 字符串是否为空#define kStringIsEmpty(str) ([...
    goyohol阅读 5,383评论 30 85
  • [转自:iOS常用宏定义][http://www.cocoachina.com/ios/20161207/1831...
    MMOTE阅读 731评论 3 3
  • 字符串是否为空 #define kStringIsEmpty(str) ([str isKindOfClass:[...
    cocoaZ阅读 319评论 0 0
  • //字符串是否为空 #define kStringIsEmpty(str) ([str isKindOfClass...
    __life__阅读 444评论 0 0
  • 远方的家 沙修 想她,就像回家 这不是童年的专利 也不是受挫的安慰 虽已三十而立 虽已成家立业 那种牵挂根植于灵魂...
    邵亓夫阅读 144评论 0 1