到目前为止,我正在使用type(of: )函数来查找变量的动态类型,并将其与Type.self进行比较以检查该类型:
var x = 5
if(type(of: x) == Int.self)
{
print("\(x) is of type Int")
}我做得对吗?或者是否有更好/更好的方法来检查类型?
发布于 2022-05-09 10:16:05
你可以使用;
if (x is Int) {
print("\(x) is of type Int")
}https://stackoverflow.com/questions/72170268
复制相似问题