What does the “unrecognized selector sent to instance” error mean?
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 c开发者_Go百科an i find the line in my code with reference 0x612b060
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.
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.
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.
- Right-Click on the executable in the Executables group in Xcode. Select
Get Info
- Select Arguments tab.
- In
Variables to be set in the environment
create a variable calledNSZombieEnabled
and set its value toYES
. Don't forget to activate it. - Turn on breakpoints and run your code.
- the debugger will point you to the object that gets released to early.
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.
Did you mean to call length
on your string?
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 ?
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 the context
object:
`EXCEPTION: <NSException: 0x55f43f93e4d0> NAME:NSInvalidArgumentException REASON:-[WOContext ASProtocolVersion]: unrecognized selector sent to instance
whereas objectForKey
works (and is the usual way to query the context
object elesewhere in the code).
See https://github.com/inverse-inc/sogo/pull/217/files
精彩评论