Swift: AnyObject cast to Float failed
问题 let json = [ "left" : 18, "deadline" : "May 10", "progress" : 0.6 ] as [String: AnyObject] let ss = json["progress"] as? Float let sss = json["progress"] as? Double print("ss = \(ss)\n sss = \(sss)") I have no idea why the ss shows nil while sss shows 0.599999998 . Why does casting to Float get nil? Do you guys have some methods so that I can get the correct result? 回答1: The 0.6 is a Double literal value . As such, you can't cast it to Float (you need to convert it). Try this instead: let f =