atik
atik

Reputation: 21

[NSCFString stringValue]: unrecognized selector sent to instance

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.

Upvotes: 2

Views: 6961

Answers (3)

PgmFreek
PgmFreek

Reputation: 6402

Please try this,

NSString *path = [NSString stringWithFormat:@"%@",c1];

Upvotes: 1

bbum
bbum

Reputation: 162722

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.

Upvotes: 3

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31730

Assume C1 is the instance of NSString.

Try with

NSString *path = [NSString stringWithString:c1];

OR

NSString *path = [[NSString alloc] initWithString:c1];

Upvotes: 0

Related Questions