加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift NSNumber 转 Sting 遇到的问题

发布时间:2020-12-14 02:09:25 所属栏目:百科 来源:网络整理
导读:编译器报错: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 { aString a . stringVal

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读