从NSCFString获取NSString [英] Getting an NSString from an NSCFString

查看:296
本文介绍了从NSCFString获取NSString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过SO,谷歌这是一个公平的位,但我不能找到我的问题的答案...

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

我有一个 NSDictionary 它返回 NSCFString的,我需要的是一个NSString,所以我可以使用它的doubleValue函数。我不能为我的生活弄清楚如何把我的 NSCFString NSString s。我试过下面没有成功:

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]];

这是控制台的输出:

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


推荐答案

NSCFString NSString ,您只需使用它作为一个。

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

由于像类集群,你不应该直接比较这里的类 - 使用 -isKindOfClass:

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

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

这篇关于从NSCFString获取NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆