首页 > 编程语言 > 详细

swift NSNumber 转 Sting 遇到的问题

时间:2015-06-09 11:49:55      阅读:689      评论:0      收藏:0      [点我收藏+]

编译器报错: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)"

swift NSNumber 转 Sting 遇到的问题

原文:http://blog.csdn.net/u011344883/article/details/46424219

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!