最佳答案
我需要将一个值存储为 Float
,但是源数据是 CGFloat
:
let myFloat : Float = myRect.origin.x
但这会导致编译器错误: ‘ NSNumber’不属于‘ Float’子类型
所以如果我这样明确地表示:
let myFloat : Float = myRect.origin.x as Float
但这反过来又会导致编译器错误: ‘无法将表达式的类型‘ Float’转换为‘ Float’’
什么是正确的方法来做到这一点,并满足编译器请?