我想为给定的类型实现类似于 CustomStringConvertible
的协议(protocol),但例如。
我的需要是显示类型属性 值,而无需为此目的创建实例评估器。当然,我可以向此类型添加 CustomStringConvertible
协议(protocol),然后创建一个实例值,仅用于调用 description
。但是不知道Swift有没有这个功能呢?
最佳答案
概述:
type(of:)
是一个返回String
中实例类型的函数
self
可以用在 Type 上
代码:
struct Something {
}
print(type(of: Something.self))
关于swift - 在 Swift 中是否有 CustomStringConvertible 等效类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44253807/