4

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 NSDictionary which is returning NSCFString's 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 NSCFString's into NSStrings. 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
49.2796758
Piyush Dubey
  • 2,416
  • 1
  • 24
  • 39
  • 1
    possible duplicate of [Obj C NSString returning class NSCFString](http://stackoverflow.com/questions/393873/obj-c-nsstring-returning-class-nscfstring) – PengOne Jun 29 '11 at 06:02

1 Answers1

12

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]]) {
    // ...
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236