部分原創(chuàng),部分網(wǎng)上
oc 禁用某個方法
- (instancetype) init NS_UNAVAILABLE;
判斷nil的宏
//只需要一個參數(shù),如果參數(shù)存在程序繼續(xù)運(yùn)行,如果參數(shù)為空,則程序停止打印日志
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]
// 覆蓋系統(tǒng)自帶的
#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輸入對應(yīng)的色值
#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)