1

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

Forge
  • 6,538
  • 6
  • 44
  • 64
Dipanjan Dutta
  • 111
  • 1
  • 4
  • 15
  • This question is almost the same as [this one](http://stackoverflow.com/questions/3645213) or [many others](http://stackoverflow.com/search?q=unrecognized+selector), did you try to search before asking? – zoul Mar 01 '11 at 09:41

6 Answers6

5

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.

Waqas Raja
  • 10,802
  • 4
  • 33
  • 38
3

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.

Forge
  • 6,538
  • 6
  • 44
  • 64
Mujah Maskey
  • 8,654
  • 8
  • 40
  • 61
2

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.

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
0

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

imz -- Ivan Zakharyaschev
  • 4,921
  • 6
  • 53
  • 104
0

Did you mean to call length on your string?

Francis McGrew
  • 7,264
  • 1
  • 33
  • 30
0

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 ?

The_Fox
  • 6,992
  • 2
  • 43
  • 69
kolek
  • 3
  • 1
  • 3
    Welcome to StackOverflow. The last part of your answer is a question. Please, use the `Ask Question` button on the mainpage. Otherwise your question will not be visible to the community. – The_Fox Sep 13 '11 at 09:53
  • The opposite to `retain` is `release`. `autorelease` gives the responsibility to call `release` for a retained object to the current autorelease pool. – Tilo Prütz Sep 14 '11 at 10:38