iOS OC中常用的宏定义

1.通用的宏定义

#ifndef define_h

#define define_h

2.获取系统对象

#define GApplication[UIApplication sharedApplication]

#define GAppWindow [UIApplication sharedApplication].delegate.window

#define GAppDelegate[AppDelegate shareAppDelegate]

#define GRootViewController[UIApplication sharedApplication].delegate.window.rootViewController

#define GUserDefaults[NSUserDefaults standardUserDefaults]

#define GNotificationCenter[NSNotificationCenter defaultCenter]

3.获取屏幕宽高

#define GScreenWidth[[UIScreen mainScreen]bounds].size.width

#define GScreenHeight[[UIScreen mainScreen]bounds].size.height

#define GScreen_Bounds[UIScreen mainScreen].bounds

4.强弱引用

#define GWeakSelf(type)__weak typeof(type)weak##type = type;

#define GStrongSelf(type)__strong typeof(type)type = weak##type;

5.DEBUG模式下打印日志,当前行

#ifdef DEBUG

#define GLog(fmt,...)NSLog((@"%s[Line %d]" fmt),__PRETTY_FUNCTION__,__LINE__,##__VA_ARGS__);

#else

#define GLog(...)

#endif

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容