• 周五. 3月 29th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

AnyObject Any AnyClass XXX.type

admin

11月 28, 2021

Swift类型信息

我们的程序加载到内存中,Swift中每个类型的信息都有一块对应内存存储着。

获取这个内存地址

// 通过类型获取
Int.self
Double.self
Person.self

// 通过类型实例获取
type(of: 类型变量/实例)
print(Person.self === type(of: person)) // true

let num = 10
print(Int.self == type(of: num))

指向类型信息变量的类型 XXX.type

let intType: Int.Type = Int.self
let personType: Person.Type Person.self

  

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注