Getting NSString from NSCFString

I read about SO and did Google it honestly, but I could not find the answer to my problem ...

I have an NSDictionary that returns NSCFString's , and I need an NSString so that I can use its doubleValue function. I cannot understand for life how to turn my NSCFString into NSString s. I tried the following without 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 console output:

 lng coord doesn't match NSString class The class of lng_coord is NSCFString 49.2796758 
+4
source share
1 answer

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

Due to patterns such as a cluster of classes , you should not directly compare classes here - use -isKindOfClass: instead:

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

All Articles