xx-li
1/26/2018 - 3:45 AM

可变参数传递

//method
+ (instancetype)test_stringWithFormat:(NSString *)format, ... {
    
    va_list argList;
    va_start(argList, format);
    NSString* message = [[NSString alloc] initWithFormat:format arguments:argList];
    if ([message containsString:@"chntel"]) {
        message = [message substringToIndex:[message rangeOfString:@"chntel"].location];
        return  message;
    }
    return message;
}

//宏
#define LOG_INFO(module, format, ...) LogInternal(kLevelInfo, module, __FILENAME__, __LINE__, __FUNCTION__, @"Info:", format, ##__VA_ARGS__)

#define LogInternal(level, module, file, line, func, prefix, format, ...) \
do { \
    if ([LogHelper shouldLog:level]) { \
        NSString *aMessage = [NSString stringWithFormat:@"%@%@", prefix, [NSString stringWithFormat:format, ##__VA_ARGS__, nil]]; \
        [LogHelper logWithLevel:level moduleName:module fileName:file lineNumber:line funcName:func message:aMessage]; \
    } \
} while(0)