winnicki winnicki - 9 months ago 55
iOS Question

Getting an NSString from an NSCFString

I read around S.O and did Google this a fair bit but I wasn't able to find an answer to my problem...

I have an

which is returning
and what I need is an NSString so that I can use its doubleValue function. I can't for the life of me figure out how to turn my
's into
s. I've tried the following with no success:

NSString* lng_coord = (NSString*)[dict objectForKey:key];
if ([lng_coord class] == [NSString class])
NSLog(@"lng coord is an exact match with NSString class");
else {
NSLog(@"lng coord doesn't match NSString class");
NSLog(@"The class of lng_coord is %@", [[dict objectForKey:key] class]);
NSLog(@"%@", lng_coord);
[CelebsAnnotation setLongitude:[lng_coord doubleValue]];

And this is the output from console:

lng coord doesn't match NSString class
The class of lng_coord is NSCFString


NSCFString is a private subclass of NSString, you can just use it as one.

Because of such patterns like class clusters, you shouldn't directly compare the classes here - use -isKindOfClass: instead:

if ([lng_coord isKindOfClass:[NSString class]]) {
    // ...