Test if object is JKArray
-
26-05-2021 - |
Pregunta
I want to see if the results of this call:
NSDictionary *results = [jsonString objectFromJSONString];
id contacts=[[results objectForKey:@"list"] objectForKey:@"Contact"];
Return an array or a dictionary.
I tried this:
[contactdict isKindOfClass:[JKArray class]];
but JKArray is statically declared in the JSONKit.m file, so the xcode can't see it.
Solución
This is what NSClassFromString
is for:
if ([contactDict isKindOfClass:NSClassFromString(@"JKArray")])
{
// do stuff here
}
Otros consejos
You may be able to simply add @class JKArray;
to the top of the file where you're making this call. That just tells the compiler that there is a class named JKArray. The actual test happens at runtime of course.
Alternatively, you should be able do this:
[[contactDict className] isEqualToString:@"JKArray"];
or this:
[contactDict isKindOfClass:NSClassFromString(@"JKArray")];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow