Reputation: 54251
This is bizarre.
Developing for the iPhone I have an NSString:
distanceFromTargetString = @"6178266.000000"
// this is not actually code, but a value taken from elsewhere. It is a proper NSString though.
When I use this
NSArray *listItems = [distanceFromTargetString componentsSeparatedByString:@"."];
distanceFromTargetString = [listItems objectAtIndex:0];
or this
[distanceFromTarget setText: distanceFromTargetString];
I get something like this
-[NSDecimalNumber isEqualToString:]: unrecognized selector sent to instance 0x1cac40
2011-07-21 14:29:24.226 AssassinBeta[7230:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDecimalNumber isEqualToString:]: unrecognized selector sent to instance 0x1cac40'
Any ideas?
Upvotes: 0
Views: 2121
Reputation: 18253
You could try to set a breakpoint at the line
[distanceFromTarget setText: distanceFromTargetString];
and see if distanceFromTargetString is actually an NSString
.
As mentioned above, somehow an NSNumber
has sneaked in somewhere.
Upvotes: 0
Reputation:
You could try :
NSInteger i = [distanceFromTargetString integerValue];
NSString s = [NSString stringWithFormat:@"%d", i];
// you got your string
Upvotes: 1
Reputation: 299385
At some point you are assigning an NSDecimalNumber
to distanceFromTargetString
rather than an NSString
. There is no run-time type checking of assignments in Objective C, so this is totally "legal":
NSDecimalNumber *number = [NSDecimalNumber ....];
[array addObject:number];
NSString *string = [array lastObject];
The above will generate no errors or warnings until you try to send NSString
methods to string
, at which point you will get an exception (crash) like you show above.
Do an audit of everywhere you assign distanceFromTargetString
, and everywhere you use NSDecimalNumber
. Somewhere you're crossing the streams.
Upvotes: 2
Reputation: 14073
You are somewhere calling isEqualToString
with a NSDecimalNumber
as the receiver. What is distanceFromTarget
? Is this an NSDecimalNumber
?
The first thing should work.
Upvotes: 1