1.宏定義的命名規(guī)范
通用常量宏
#define AMK_NAVIGATIONBAR_HEIGHT 64
私有常量宏
#define kCFCoreFoundationVersionNumber_iOS_7_0 847.20
配置類常量宏
#define MJRefreshColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define MJRefreshLabelTextColor MJRefreshColor(90, 90, 90)
#define MJRefreshLabelFont [UIFont boldSystemFontOfSize:14]
通用操作宏
#define MAX(A,B) __NSMAX_IMPL__(A,B,__COUNTER__)
#define MAS_NSUINT_BIT (CHAR_BIT * sizeof(NSUInteger))
#define MAS_NSUINTROTATE(val, howmuch) ((((NSUInteger)val) << howmuch) | (((NSUInteger)val) >> (MAS_NSUINT_BIT - howmuch)))
模板宏
#define MAS_ATTR_FORWARD(attr) \
- (MASViewAttribute *)attr { \
return [self mas_##attr]; \
}
方法簡(jiǎn)寫宏
#define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value))
#define UIImageNamed(name) [UIImage imageNamed:(name)]
#define NSParameterAssert(condition) NSAssert((condition), @"Invalid parameter not satisfying: %@", @#condition)
#define MJExtensionDeprecated(instead) NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, instead)
#define MJRefreshSrcName(file) [@"MJRefresh.bundle" stringByAppendingPathComponent:file]
#define MJRefreshFrameworkSrcName(file) [@"Frameworks/MJRefresh.framework/MJRefresh.bundle" stringByAppendingPathComponent:file]
#define MAS_VIEW UIView
#define MASEdgeInsets UIEdgeInsets
#define MASMethodNotImplemented() \
@throw [NSException exceptionWithName:NSInternalInconsistencyException \
reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] \
userInfo:nil]
#define MASAttachKeys(...) \
NSDictionary *keyPairs = NSDictionaryOfVariableBindings(__VA_ARGS__); \
for (id key in keyPairs.allKeys) { \
id obj = keyPairs[key]; \
NSAssert([obj respondsToSelector:@selector(setMas_key:)], \
@"Cannot attach mas_key to %@", obj); \
[obj setMas_key:key]; \
}
特定類中的步驟簡(jiǎn)稱
#define mas_equalTo(...) equalTo(MASBoxValue((__VA_ARGS__)))
#define mas_greaterThanOrEqualTo(...) greaterThanOrEqualTo(MASBoxValue((__VA_ARGS__)))
#define mas_lessThanOrEqualTo(...) lessThanOrEqualTo(MASBoxValue((__VA_ARGS__)))
#define mas_offset(...) valueOffset(MASBoxValue((__VA_ARGS__)))
其他
內(nèi)部的导绷、較隱晦的常量宏缘屹、操作宏、方法宏等步淹,在上述的基礎(chǔ)上阻塑,在前面追加"__"(下劃線)
#define __IPHONE_OS_VERSION_MIN_REQUIRED __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__
一系列相同格式的宏
#define NSFoundationVersionNumber_With_Fixed_5871104061079552_bug 1140.11
2.靜態(tài)/常量 值的聲明與定義
字符串
// 聲明
FOUNDATION_EXPORT NSString *const AMKCommonErrorDomain;
// 或
// extern NSString *const AMKCommonErrorDomain;
// 賦值
NSString *const AMKCommonErrorDomain = @"COM.ANDY.OC.AMKIT.COMMON_ERROR_DOMAIN";
3.方法的命名
(未完待續(xù)...)