“无法识别的选择器发送到实例”是什么意思?错误是什么意思?
由于以下错误,我的应用程序崩溃了:
-[NSCFString count]: unrecognized selector sent to instance 0x612b060
任何人都可以告诉我这是什么意思以及如何在代码中找到引用 0x612b060 的行
I am getting a crash in my app due to the following error:
-[NSCFString count]: unrecognized selector sent to instance 0x612b060
Can anybody tell me what does it mean and how can i find the line in my code with reference 0x612b060
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您正在对已释放或尚未初始化的对象(可能是数组、字典或集合等集合)调用
count
方法。You are calling
count
method on an object (probably a collection e.g array, dictionary, or set) which is released or has not been initialized yet.您正在 NSCFString 上发送消息“count”,意味着在 NSString 数据类型上调用“count”方法。
要查找代码,您可以使用堆栈跟踪,但我确信您正在做的是:
在 NSArray 或(数组数据类型)上分配 NSString 数据并尝试计数。
You are sending message "count" on NSCFString, means, calling "count" method on NSString datatype.
To find the code, you can use Stack trace, but I am sure what you are doing is:
Assign NSString data on NSArray or (Array datatype) and trying to count.
发生这种情况很可能是因为您没有正确保留一个集合对象(例如 NSArray、NSDictionary)。
尝试使用 NSZombies 来查找被释放的对象。
获取信息
要在环境中设置的变量
中创建一个名为NSZombieEnabled
的变量,并将其值设置为YES
。不要忘记激活它。调试完此问题后,您应该停用 NSZombies。 NSZombies 不会释放任何内存,它只是将对象标记为已释放。
所以你迟早会遇到内存警告。
您只需删除其前面的复选标记即可停用 NSZombies。
Most likely this happens because you have a collection object (eg NSArray, NSDictionary) that you do not retain properly.
Try to use NSZombies to find the object that got released.
Get Info
Variables to be set in the environment
create a variable calledNSZombieEnabled
and set its value toYES
. Don't forget to activate it.After you've done debugging this problem you should deactivate NSZombies. NSZombies won't release any memory, it just marks the objects as released.
So you will end up in a memory warning sooner or later.
You can simply remove the checkmark in front of it to deactivate NSZombies.
您的意思是在字符串上调用
length
吗?Did you mean to call
length
on your string?也许有人会需要这个:
当我遇到此类问题时,我使用了:
[myarray 保留];
后
myarray = [NSArray arrayWithObjects: ...];
它起作用了。我认为这是因为我的阵列太早自我毁灭了。
但我不知道现在如何释放这个对象?
只是
[myarray autorelease]
?有什么相反的东西可以保留吗?Maybe someone will need this:
When I had this kind of problem I used:
[ myarray retain];
after
myarray = [NSArray arrayWithObjects: ...];
and it worked. I think it was because my array destroying itself too early.
But I don' t know how I can now release this object?
Just
[myarray autorelease]
? Is there something opposite to retain ?一个实际的例子:
有时,存在一个我还不太清楚的实际差异。
valueForKey
在 SOGo-3.1.4 的代码中不起作用,试图在context
对象上调用不可用的“方法”ASProtocolVersion
:而
objectForKey
有效(并且是在代码中其他位置查询context
对象的常用方法)。请参阅 https://github.com/inverse-inc/sogo/pull/217/文件
A practical example:
Sometimes, there is a practical difference which I don't understand clearly yet.
valueForKey
didn't work in SOGo-3.1.4's code trying to call an unavailable "method"ASProtocolVersion
on thecontext
object:whereas
objectForKey
works (and is the usual way to query thecontext
object elesewhere in the code).See https://github.com/inverse-inc/sogo/pull/217/files