swift 类型变量、元类型、类型
元类型的声明:
let x:String.Type
类型的获取:
type(of)、SomeBaseClass.self
let someInstance: SomeBaseClass = SomeSubClass()
| |
compileTime Runtime
| |
To extract, use: .self type(of)
对象 类 类的元类型
type(of:someInstance) type(of:SomeBaseClass)
类型的表达:SomeBaseClass、SomeBaseClass.Type、SomeBaseClass.Type
变量的表达: someInstance、type(of:someInstance)==SomeBaseClass.self、type(of:SomeBaseClass)
print(String.self)
print(type(of: greeting))
print(type(of: type(of: greeting)))
print(type(of: type(of: type(of: greeting))))
String
String
String.Type
String.Type.Type
print(String.self is String.Type) == true
判断力是一个人最重要的能力

浙公网安备 33010602011771号