代码基于:swift 4.0
- 在一个类中,可以通过 customClass.self 取出不带命名空间的类名。
print(self) // <testOne.ViewController: 0x1033094f0>
print(self.description) // <testOne.ViewController: 0x101d10350>
print(ViewController.self) // ViewController
po type(of: self) // testOne.ViewController
print(type(of: self)) // ViewController
- type(of:)得到是类型
let count: Int = 5
printInfo(count)
// '5' of type 'Int'
本文介绍在Swift4.0中如何通过不同方法获取类的名称和类型,包括使用self、description、type(of:)等,展示了实际代码示例。

1500

被折叠的 条评论
为什么被折叠?



