How to determine the type of a variable in Swift

前端 未结 5 1491
你的背包
你的背包 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:27

    I use breakpoints during debuging but if you need to check if they match a certain type during runtime then drewag is right

    another thing you can do is test datatype with assertion this would only work in debugging but with assertion you can set conditions which if met app crashes

    maybe something like assert(let tArray == oldArray as? NSArray[] //if not NSArray app crashes)

提交回复
热议问题