Objective-c – [NSCFString stringValue]: unrecognized selector sent to instance

iphoneobjective c

My created application crashed when executing the below lines of code
where c1 is an integer variable.

NSString *path = c1.stringValue;

Shows the following error in log:

-[NSCFString stringValue]: unrecognized selector sent to instance
0x5566e80 2011-05-11 14:56:15.813
e-TREND[1552:207] Uncaught Exception
happens!! (NSInvalidArgumentException:
-[NSCFString stringValue]: unrecognized selector sent to instance
0x5566e80) 2011-05-11 14:56:15.816
e-TREND[1552:207] * Terminating app
due to uncaught exception
'NSInvalidArgumentException', reason:
'-[NSCFString stringValue]:
unrecognized selector sent to instance
0x5566e80'

if anyone have any idea to solve this issue , please answer accordingly.

Best Answer

where c1 is an integer variable

What does that mean? How is c1 declared?

If c1 were an int, then c1.stringValue wouldn't even compile.

The dot syntax only works when the object reference -- c1 -- is of a specific object reference type (not id) and that reference-- that class-- responds to the method.

So, you have something like:

MyThingThatRespondsToStringValue *c1;

And then you are, somewhere, assigning an instance of NSString to that variable which leads to the crash.