快速开发经验汇总小结(洪)

//字符串是否为空

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

//数组是否为空

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

//字典是否为空

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

//是否是空对象

#define YObjectIsEmpty(_object) (_object == nil \

||[_objectisKindOfClass:[NSNullclass]]\

||([_objectrespondsToSelector:@selector(length)]&&[(NSData*)_objectlength]==0)\

||([_objectrespondsToSelector:@selector(count)]&&[(NSArray*)_objectcount]==0))

//一些缩写

#define YApplication        [UIApplication sharedApplication]

#define YKeyWindow          [UIApplication sharedApplication].keyWindow

#define YAppDelegate        [UIApplication sharedApplication].delegate

#define YUserDefaults       [NSUserDefaults standardUserDefaults]

#define YNotificationCenter [NSNotificationCenter defaultCenter]

// 通知

// 注册通知

#define NOTIFY_ADD(_noParamsFunc, _notifyName)  [[NSNotificationCenter defaultCenter] \

addObserver:self \

selector:@selector(_noParamsFunc) \

name:_notifyName \

object:nil];

// 发送通知

#define NOTIFY_POST(_notifyName)  [[NSNotificationCenter defaultCenter] postNotificationName:_notifyName object:nil];

// 移除通知

#define NOTIFY_REMOVE(_notifyName) [[NSNotificationCenter defaultCenter] removeObserver:self name:_notifyName object:nil];

#define YImageNamed(s)  [UIImage imageNamed:s]


//APP版本号

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

//系统版本号

#define YSystemVersion [[UIDevice currentDevice] systemVersion]

//获取沙盒Document路径

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

//获取沙盒temp路径

#define YTempPath NSTemporaryDirectory()

//获取沙盒Cache路径

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

//判断是真机还是模拟器

#if TARGET_OS_IPHONE

//真机

#endif

#if TARGET_IPHONE_SIMULATOR

//模拟器

#endif

//开发的时候打印,但是发布的时候不打印的NSLog

#ifdef DEBUG

#define NSLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])

#else

#define NSLog(...)

#endif

//颜色

#define YRGBColor(r, g, b)     [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

//由角度转换弧度

#define kDegreesToRadian(x)      (M_PI * (x) / 180.0)

//由弧度转换角度

#define kRadianToDegrees(radian) (radian * 180.0) / (M_PI)

//获取一段时间间隔

#define kStartTime CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();

#define kEndTime   NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start)

// 导航

#define PUSH(VC) [self.navigationController pushViewController:VC animated:YES];

#define POPVC [self.navigationController popViewControllerAnimated:YES];

#define POPTOROOT [self.navigationController popToRootViewControllerAnimated:YES];

持续更新小结

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

推荐阅读更多精彩内容