在 Instruments 中运行的 iPhone 应用程序因无法识别的选择器而失败

发布于 2024-08-02 00:21:52 字数 568 浏览 4 评论 0原文

我有一个应用程序,在正常使用中似乎运行没有问题。 Clang Static Analyzer 也没有报告任何问题。 当我尝试在 Instruments 中运行它时,它失败并出现无法识别的选择器异常。

有问题的行是一个简单的属性设置器,其形式为:

self.bar = baz;

为了弄清楚发生了什么,我在其上方添加了一个 NSLog() 调用:

NSLog(@"class = %@ responds = %d", [self class], [self respondsToSelector:@selector(setBar:)]);
self.bar = baz;

在模拟器(没有仪器)和设备上,这准确地显示了我所期望的内容:

class = Foo responds = 1

在 Instruments 下运行时,我得到:

class = Foo responds = 0

我很困惑什么会导致这种情况。 当仪器环境中时,是否可能会占用不同的内存位置? 谁能建议我如何调试这个?

I have an app that appears to run without problems in normal use. The Clang Static Analyzer reports no problems either. When I try to run it in Instruments, it fails with an unrecognized selector exception.

The offending line is a simple property setter of the form:

self.bar = baz;

To figure out what's going on, I added an NSLog() call immediately above it:

NSLog(@"class = %@ responds = %d", [self class], [self respondsToSelector:@selector(setBar:)]);
self.bar = baz;

On the emulator (without Instruments) and on a device, this shows exactly what I'd expect:

class = Foo responds = 1

When running under Instruments, I get:

class = Foo responds = 0

I'm stumped as to what could cause this. Perhaps a different memory location is getting tromped on when it's in the Instruments environment? Can anyone suggest how I might debug this?

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

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

发布评论

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

评论(3

も星光 2024-08-09 00:21:52

如果 bar 属于 self,你不能这样做 bar=baz; 吗?

If bar belongs to self, can't you do bar=baz; ?

沒落の蓅哖 2024-08-09 00:21:52

检查你的财产。
也许你需要巴兹的演员阵容?

Check your properties.
Perhaps to you need a cast on baz?

无戏配角 2024-08-09 00:21:52

这里没有足够的信息来了解发生了什么,但是,如果您知道要提供哪些信息,您可能已经修复了它。 所以。 有几件事需要检查:

  • “self”指针是否以任何方式被混淆? 为了理智起见,尝试在不同点打印出 self 的值
  • 当您的代码在 Instruments 中运行时,它是否以不同的模式运行? (32 位与 64 位、垃圾收集与保留释放等)我不确定为什么其中任何一个都会产生影响,但如果它以不同的模式运行,那就需要研究一下。
  • 您是否正确合成了 setter? 或者它是动态提供的(通过核心数据等)? 如果您手动指定 setBar: 方法,您还会收到错误吗?

There's not enough information here to know what's going on, but then, if you knew what information to provide you'd probably have already fixed it. So. A few things to check:

  • Is the "self" pointer being swizzled in any way? Try printing out the value of self at various points just for sanity's sake
  • When your code runs in Instruments, is it running in a different mode? (32-bit vs. 64-bit, Garbage collected vs. Retain-Release, etc.) I'm not sure why any of those would have an effect, but if it's running in a different mode, that's something to look into.
  • Are you synthesizing the setter correctly? Or is it being provided dynamically (via Core Data, etc.)? If you manually specify a setBar: method, do you still get the error?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文