个人对宏定义命名规范的理解

1.宏定义的命名规范

通用常量宏
#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];   \
}
方法简写宏
#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];                                                 \
}
特定类中的步骤简称
#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__)))
其他

内部的、较隐晦的常量宏、操作宏、方法宏等,在上述的基础上,在前面追加"__"(下划线)

#define __IPHONE_OS_VERSION_MIN_REQUIRED __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__
一系列相同格式的宏
#define NSFoundationVersionNumber_With_Fixed_5871104061079552_bug 1140.11

2.静态/常量 值的声明与定义

字符串
//  声明
FOUNDATION_EXPORT NSString *const AMKCommonErrorDomain;
//  或
//  extern NSString *const AMKCommonErrorDomain;

//  赋值
NSString *const AMKCommonErrorDomain = @"COM.ANDY.OC.AMKIT.COMMON_ERROR_DOMAIN";

3.方法的命名

(未完待续...)

你可能感兴趣的:(个人对宏定义命名规范的理解)