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

你可能感兴趣的:(iOS OC中常用的宏定义)