是否可能从Swift language
的类中检索数据Type
?从类中获取类型
这是一个例子:
class Test : NSObject
{
let field1 : String
let field2 : Int
init(value1 : String, value2 : Int)
{
field1 = value1
field2 = value2
}
}
let test1 = Test(value1: "Hello", value2: 1)
//this code return the same string with class name (__lldb_expr_129.Test)
let classString = NSStringFromClass(test1.classForCoder)
let className2 = reflect(test1).summary
//this code return the same ExistentialMetatype value and not the Tes or NSObject type
let classType = reflect(test1).valueType
let classType2 = test1.self.classForCoder
//this return Metatype and not the Test or NSObject type
let classType3 = test1.self.dynamicType
是否有以检索所述Test
类型,而不是ExistentialMetatype
或Metatype
值的方法?
可能重复[如何在Swift中打印变量的类型或类?](http://stackoverflow.com/questions/24006165/how-do-i-print-the-type-or快速变化的类) – 2014-09-29 14:10:57