ios - iOS中宏的误区

标签 ios xcode macros header-files

有些东西我根本不明白,因为我一辈子都无法让它发挥作用。我想创建一个扩展 NSLog(NSString *format, ...) 的宏。这是我想出的:

NSLogExtensions.h

#define DebugLog(debugMode, format, ...) MyDebugLog(debugMode, [[NSString stringWithFormat:@"<%@> (Line %d): ", NSStringFromClass([self class]), __LINE__] stringByAppendingString:format], ##__VA_ARGS__)

@interface NSLogExtensions : NSObject

@end

NSLogExtensions.m

#import "NSLogExtensions.h"

@implementation NSLogExtensions

void MyDebugLog(bool debugMode, NSString *format, ...) {
    va_list(argumentList);
    va_start(argumentList, format);
    if (debugMode) {
        NSLogv(format, argumentList);
    }
    va_end(argumentList);
}

@end

我希望能够包含 NSLogExtensions 头文件,然后能够使用宏,但我仍然收到 GCC 隐式函数声明警告。

最佳答案

检查这个答案

Is it true that one should not use NSLog() on production code?

它有更多关于如何为扩展的 NSLogs 使用宏的详细信息

关于ios - iOS中宏的误区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11764066/

相关文章:

c++ - C 中特定的 toSquare 函数

objective-c - mfmailcomposer 剪切 html 电子邮件的结尾

ios - AFNetworking 依次上传多个文件

objective-c - UIDatePicker 使用模式作为计时器

我们可以删除 C 宏定义中参数周围的括号吗?

macros - Clojure:def 在顶层之外使用时丢弃 ^:macro

ios - Swift:线程 1:EXC_BAD_ACCESS 即使有 guard

ios - 从子 UIVIewController 控制 UIScrollView

ios - react native : ios - Library not found for -lbolts

ios - 无法使用 appium 1.6.0 在 IOS 10 真实设备中启动 ipa 文件