How to determine the type of a variable in Swift

前端 未结 5 1488
你的背包
你的背包 2020-12-04 21:59

Is there a function to determine the variable type in Swift? I presume there might be something like like type() in Python.

I\'d like a way to judge if

5条回答
  •  渐次进展
    2020-12-04 22:05

    Someone mentioned this above, but I think it deserves visibility as an answer rather than a comment. You can now simply use type(of: ___):

    var red, green, blue: Double
    print(type(of: green))
    

    yields

    Double

提交回复
热议问题