部分原创,部分网上
oc 禁用某个方法
- (instancetype) init NS_UNAVAILABLE;
判断nil的宏
//只需要一个参数,如果参数存在程序继续运行,如果参数为空,则程序停止打印日志
NSParameterAssert(str);
懒加载
#ifndef PCH_LazyLoading
#define PCH_LazyLoading(_type_, _ivar_) \
- (_type_ *)_ivar_ { \
if (! _##_ivar_) { \
_##_ivar_ = [[_type_ alloc] init]; \
} \
return _##_ivar_; \
}
#endif
#ifndef PCH_LazyLoadingBlock
#define PCH_LazyLoadingBlock(_type_, _ivar_ ,block) \
- (_type_ *)_ivar_{\
void(^initBlock)(_type_ *_ivar_) = ^(_type_ *_ivar_) block;\
if (!_##_ivar_) {\
_type_ *_ivar_ = [[_type_ alloc] init];\
_##_ivar_ = _ivar_;\
initBlock(_ivar_);\
}\
return _##_ivar_;\
}
#endif
debug
#define Debug_BaseViewControllerCreated(str) [[NSClassFromString(str) alloc] init]
// 覆盖系统自带的
#ifdef DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif
color
#define PCH_CUSTUM_COLOR(y) [UIColor colorWithRed:((float)((y & 0xFF0000) >> 16))/255.0 green:((float)((y & 0xFF00) >> 8))/255.0 blue:((float)(y & 0xFF))/255.0 alpha:1.0] //custumcolor输入对应的色值
#define PCH_CUSTOM_BLUE_COLOR PCH_CUSTUM_COLOR(0x15B0C9)
frame
#define PCH_SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#define PCH_SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define PCH_SIZE_SCREEN_HEIGHT (PCH_SCREEN_HEIGHT/667)
#define PCH_SIZE_SCREEN_WIDTH (PCH_SCREEN_WIDTH/375)
//像素为单位的 不需要自己除以2
#define PCH_BitMap_BY_SIZE(height) (((height)/2)*PCH_SIZE_SCREEN_WIDTH)