gpt4 book ai didi

ios - ios 自定义框架中的宏定义不起作用

转载 作者:行者123 更新时间:2023-11-29 12:59:01 24 4
gpt4 key购买 nike

可以请任何人告诉如何在 ios 中构建框架时通过打印一些信息来控制台来使用 debuglog 等宏,并且当应用程序开发人员在 Debug模式下使用此框架运行应用程序时它应该可以工作。

最佳答案

1) 在你的库中用一些奇怪的名字定义一个全局 BOOL:

BOOL GzRkYr22; // (use your framework name as prefix or suffix)

2) 为您的用户提供一些方法来打开或关闭标志:

- (void)enabledDebuggingMessages:(BOOL)val;

该方法将设置全局标志。

3) 将其放入您的 .pch 文件

extern BOOL GzRkYr22;

#define Log(format, ...) \
do { if(GzRkYr22 ) NSLog(format, \
## __VA_ARGS__); \
} while(NO)

4) 在您的代码中添加日志消息:

Log(@"Just did %d operations", someNumber);

5) 如果您后来决定只为您的库的“调试”版本提供日志消息,但对于“生产”版本则完全禁用它们:

#ifndef NDEBUG // some macro that is defined or not defined for the different modes

#define Log(format, ...) \
do { if(GzRkYr22 ) NSLog(format, \
## __VA_ARGS__); \
} while(NO)

#else

#define Log(format, ...)

#endif

关于ios - ios 自定义框架中的宏定义不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20251116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com