问题描述
我读过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 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]];
这是控制台的输出:
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.
由于像,你不应该直接比较这里的类 - 使用:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!