如何调试Objective-C中的单例 [英] How do I debug singletons in Objective-C

查看:131
本文介绍了如何调试Objective-C中的单例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用包含几个单身人士(以下是本教程)。然而,我注意到,当应用程序因为单身失败而崩溃时,几乎不可能弄清楚它来自哪里。即使问题出现在Singleton对象之一中,主函数的应用程序断点也提供EXEC_BAD_ACCESS。有没有指导我如何调试我的单身对象,如果他们有问题?

My app contains several singletons (following from this tutorial). I've noticed however, when the app crashes because of a singleton, it becomes nearly impossible to figure out where it came from. The app breakpoints at the main function giving an EXEC_BAD_ACCESS even though the problem lies in one of the Singleton objects. Is there a guide to how would I debug my singleton objects if they were problematic?

推荐答案

我扫描了文章,而有一些好的想法也有一些不好的建议,它不应该被当作福音。

I scanned the article, and while it had some good ideas it also had some bad advice, and it should not be taken as gospel.

而且,正如其他人所建议的,如果你有很多单身对象这可能意味着你只是保持太多的状态全局/持续。通常只需要一个或两个你自己的(除了那些其他可能实现的包之外)。

And, as others have suggested, if you have a lot of singleton objects it may mean that you're simply keeping too much state global/persistent. Normally only one or two of your own should be needed (in addition to those that other "packages" of one sort or another may implement).

关于调试单例,我不明白为什么你说这很难 - 绝对不会比别的更糟糕,大部分情况。如果你收到EXEC_BAD_ACCESS,那是因为你有一些解决方案的bug,而且这对单身份的计划没有任何特殊的影响(除非你使用的是非常糟糕的)。

As to debugging singletons, I don't understand why you say it's hard -- no worse than anything else, for the most part. If you're getting EXEC_BAD_ACCESS it's because you've got some sort of addressing bug, and that's nothing specific to singleton schemes (unless you're using a very bad one).

宏使调试变得困难,因为它们包含的代码行不能在其中插入断点。深六个宏,如果没有别的。特别地,文章中的 SYNTHESIZE_SINGLETON_FOR_CLASS 宏正在干扰调试。将此宏函数的调用替换为您的单例类生成的代码。

Macros make debugging difficult because the lines of code they incorporate can't have breakpoints put in them. Deep six macros, if nothing else. In particular, the SYNTHESIZE_SINGLETON_FOR_CLASS macro from the article is interfering with debugging. Replace the call to this macro function with the code it generates for your singleton class.

这篇关于如何调试Objective-C中的单例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆