开发者

What does the “unrecognized selector sent to instance” error mean?

开发者 https://www.devze.com 2023-02-14 14:41 出处:网络
I am getting a crash in my app due to the following error: -[NSCFString count]: unrecognized selector sent to instance 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 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.

  1. Right-Click on the executable in the Executables group in Xcode. Select Get Info
  2. Select Arguments tab.
  3. In Variables to be set in the environment create a variable called NSZombieEnabled and set its value to YES. Don't forget to activate it.
  4. Turn on breakpoints and run your code.
  5. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消