I have code distributed in a library which looks like this:
if ([[NSString class] instancesRespondToSelector: @selector(JSONValue)]) {
NSString *jsonString = [[[NSString alloc] initWithData: jsonData encoding: NSUTF8StringEncoding] autorelease];
dict = [jsonString performSelector: @selector(JSONValue)];
}
For some reason a -[__NSCFString JSONValue]: unrecognized selector sent to instance
exception is getting thrown when the performSelector:
method gets called. This is code that is distributed in a library that I wrote, but I can't reproduce or debug it myself. Instead a third-party is reporting this problem. Under what conditions could instancesRespondToSelector:
while actually calling the method using performSelector:
throw an exception?
edit There is a case which could explain why this occurs, but it doesn't make sense. If the developers were to do something like this:
@implementation NSString (OurHappyCategory)
+ (BOOL)instancesRespondToSelector:(SEL)aSelector
{
return YES;
}
@end
It would explain why the code is executing, but it would of course be a very bad thing to do. Is there a way this problem could occur that makes sense?
JSONValue
method isid
. – Plataif
clause? – EspeciallyJSONValue
? Maybe the 3rd-party is not linking your lib proper and callingJSONValue
by themself? – DebaucheeJSONValue
, so I don't think that is the problem. It is possible they changed theNSString
class's behavior, but I don't understand why they would. – PlataJSONValue
category, which wouldn't be uncommon. – WhiffenJSONValue
thatNSString
implements, why would it throw an exception? – Plata-ObjC
flag then instancesRespondToSelector: will return NO. If you do use the-ObjC
flag theninstancesRespondToSelector:
will return YES and no exception will get thrown.-all_load
has the same effect as-ObjC
. – Plata