swift NSNumber 转 Sting 遇到的问题

前端之家收集整理的这篇文章主要介绍了swift NSNumber 转 Sting 遇到的问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

编译器报错:Could not cast value of type '__NSCFNumber' (0x...) to 'NSString' (0x...).


解决方案:

The value is anNSNumber,not anNSString. You can usestringValueto convert it:

if let a = d["a"]as? NSNumber { aString  a.stringValue println(aString) // -1}

If you're sure it's there,you can use forced unwrapping and string interpolation:

]!! "\(a)"

猜你在找的Swift相关文章