데이터 Type
을 Swift language
에 다시 가져올 수 있습니까?클래스에서 유형 가져 오기
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) -class-of-a-variable-in-swift) –