Reputation: 64834
This code
if ( [currentValue isKindOfClass:NSClassFromString(@"NSString")] ) {
CBDebug(@"this is a string");
works well when the type of currentValue is __NSCFString
but it doesn't recognize the string if the type is __NSCFConstantString
How can I fix it ? (I'm on OSX)
thanks
Upvotes: 1
Views: 635
Reputation: 22930
Try this [obj isKindOfClass:[NSString class]];
Normally you only need NSClassFromString
when testing for class names that may not be available to you.
Note: Be careful when using isKindOfClass:
method on objects represented by a class cluster. Because of the nature of class clusters, the object you get back may not always be the type you expected. isKindOfClass:
will return YES if the receiver somewhere inherits from the class passed as argument.
Upvotes: 0
Reputation: 2278
Instead of checking the textstring of the class, do try the following:
[myObject isKindOfClass:[NSString class]]
Upvotes: 3
Reputation: 15218
Try this:
if ( [currentValue isKindOfClass:[NSString class]] ) {
CBDebug(@"this is a string");
}
Upvotes: 4