码迷,mamicode.com
首页 > 编程语言 > 详细

swift NSNumber 转 Sting 遇到的问题

时间:2015-06-09 11:51:50      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:nsnumber   sting   

编译器报错: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 遇到的问题

标签:nsnumber   sting   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!