编译器报错:Could not cast value of type '__NSCFNumber' (0x...) to 'NSString' (0x...).
解决方案:
The value is anNSNumber
,not anNSString
. You can usestringValue
to 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)"原文链接:https://www.f2er.com/swift/326995.html