NSNumber [numberWithInt:] EXC_BAD_ACCESS?
在我的应用程序中,我在 Singleton 中保存了一个从 ClassA 设置的 int 。然后在 ClassB 中,我从 Singleton 中获取该 int,如下所示:
int myInt = [Singleton sharedSingleton].scoreInt;
然后,由于 NSDictionary
仅支持 NSNumber
而不是 int,我这样做:
NSDictionary *theDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:myInt], @"Score", nil];
问题是我总是得到 EXC_BAD_ACCESS错误。控制台中唯一显示的是蓝色的 (gdb)。我还将 NSZombieEnabled 设置为 ON。
myInt 不为零,已通过 NSLogs 确认。这有什么原因吗?我该如何解决这个问题?
谢谢!
In my app I hold a int in a Singleton which I set from ClassA. Then in ClassB I grab that int from the Singleton like so:
int myInt = [Singleton sharedSingleton].scoreInt;
Then, since NSDictionary
only supports NSNumber
and not int, I do this:
NSDictionary *theDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:myInt], @"Score", nil];
The problem is that I always get EXC_BAD_ACCESS error. The only thing that shows up in the console is (gdb) in blue. I also have NSZombieEnabled set to ON.
myInt is not nil, confirmed with NSLogs. Is there any reason for this? How can I fix this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论