简体   繁体   中英

Getting an NSString from an NSCFString

I read around SO 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 NSString 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
49.2796758

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]]) {
    // ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM