我想知道我稍后初始化的AnyObject变量的类型是什么.
例如:
例如:
var test: AnyObject test = 12.2
我无法弄清楚如何做到这一点.
您可以使用is运算符执行此操作.
示例代码:
示例代码:
var test: AnyObject
test = 12.2
if test is Double {
println("Double type")
} else if test is Int {
println("Int type")
} else if test is Float {
println("Float type")
} else {
println("Unkown type")
}
根据Apple文档:
Checking Type
Use the type check operator (is) to check whether an instance is of a certain subclass type. The type check operator returns true if the instance is of that subclass type and false if it is not.