框架类中有条件编译的 NSLog 替代方案,可在框架外使用

发布于 2024-10-19 15:27:28 字数 311 浏览 5 评论 0原文

我有一个 NSLog 替代方案,它输出调用它的类以及 PLogging 类中名为 PLog 的行号和方法(选择器)。它与此处 除了名称更改之外。 DLog 的优点是,在发布模式下编译时,日志调用将更改为注释,从而消除了您可能受到的性能影响。我希望能够使用它并将其保留在框架内,但能够从我添加框架的项目中调用它。但在发布模式下仍将日志调用编译为注释。这可能吗?

I have an NSLog alternative that outputs the class it's called from as well as the line number and method (selector) called PLog in a class called PLogging. It's the exact same as the DLog taken from here with the exception of the name change. The advantage of DLog as it is written is that when compiled under Release mode, the log call is changed to a comment, negating the performance impact you would otherwise be subject to. I want to be able to use this and keep it within the framework, but be able to call it from the projects I add the framework to. But still have the log calls compiled to comments when in Release mode. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雪若未夕 2024-10-26 15:27:29

我建议采用白名单方法:将预处理器定义添加到调试配置中,使 DLog/Plog 能够记录到控制台。在所有其他情况下,它都会转向评论。

请查看这篇博文,它似乎指出了您的问题。当然,假设您不想改变实现功能的方式:宏。我引用 abit:“基本问题的一个例子是您想要链接到一个同时具有调试版本和发布版本的库。因此,在您的应用程序中,您希望调试版本链接到库的调试版本,并且您希望您的发布版本链接到库的发布版本。”

我宁愿倾向于使用目标来实现这一点,但麻烦确实看起来不舒服。

I would suggest a white list approach: add a preprocessor definition to your debug configurations which enables DLog/Plog to log to the console. In every other case it turns to comments.

Please have a look at this blog post which seems to point a finger at your problem. Of course, assuming that you don't want to change the way you are achieving your functionality: macros. I'm quoting abit: "An example of the basic problem is you want to link to a library that has both a Debug and a Release version. So in your application you want your Debug version to link to the Debug version of the library, and you want your Release version to link the Release version of the library."

I would rather tend to use targets for that, the trouble does look uncomfortable.

二货你真萌 2024-10-26 15:27:29

App Store 不允许使用第三方框架。我假设您有一个静态库或源文件,可以通过跨项目引用添加到您的应用程序中?

如果您已经为库项目设置了为调试配置设置的调试标志,并为发布配置取消设置,那么您所要做的就是为应用程序项目使用相同的配置名称,并且将使用以下内容构建库相同的配置。

Third-party frameworks aren't allowed by the App Store. I assume you've got a static library or source files that you add to your apps with a cross-project reference?

If you've set your library project up with a debug flag set for your Debug configuration and unset for your Release configuration, then all you have to do is use the same configuration names for your app project, and the library will be built with the same configuration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文