您的位置:首页 > 移动开发 > Swift

swift NSNumber 转 Sting 遇到的问题

2015-06-09 11:09 344 查看
编译器报错:Could not cast value of type '__NSCFNumber' (0x...) to 'NSString' (0x...).

解决方案:

The value is an
NSNumber
,
not an
NSString
.
You can use
stringValue
to
convert it:
if let a = d["a"] as? NSNumber {
let aString = a.stringValue
println(aString) // -1
}


If you're sure it's there, you can use forced unwrapping and string interpolation:
let a = d["a"]! as! NSNumber
let aString = "\(a)"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: