Eureka表单值返回可选值,所以我想遍历每个值并将其解包。但是,这些值由Double,Int,String组成。如何将它们解包为String?
let wrapped = self.formValues()
var unwrapped = [String:Any]()
for (k,v) in wrapped {
unwrapped[k] = v as! String ?? ""
}
return unwrapped
我收到此错误:
Could not cast value of type 'Swift.Double' (0x7fff879c1a10) to 'Swift.String' (0x7fff879c41c8).
替换
v as! String ?? ""
with
String(v)