swift 5.x 版本
类型 | 打印 |
---|---|
refrence type引用类型 |
print(Unmanaged.passUnretained(testType).toOpaque()) 替换testType为你的引用类型 |
object instance,metatype |
print(ObjectIdentifier(testType)) testType 为你的类型 |
value type 值类型 |
print(UnsafePointer(&testType)) 替换testType 为你的类型 |
struct PersonS {
}
class Friend: CustomStringConvertible{
var name: String = "Friend"
var description: String {
return "name = \(name)"
}
}
class Person: CustomStringConvertible {
var age: Int = 20
var friend: Friend = Friend()
var description: String {
return "age = \(age) friend: + \(friend.description)"
}
}
let lee = Person()
lee.friend.name = "lee"
let han = lee
han.friend.name = "lee"
han.age = 21
print(lee)
print(han)
var ps = PersonS()
// 引用类型
print(Unmanaged.passUnretained(han).toOpaque()) //打印引用类型
print(Unmanaged.passUnretained(lee).toOpaque()) //打印引用类型
print(UnsafePointer(&ps)) //打印地址 值类型
//ObjectIdentifier 支持实例,元类型,不支持 enum, struct,func,tuple
print(ObjectIdentifier(Person.self)) // 打印 元类型
print(ObjectIdentifier(han)) // 打印 对象实例
print(ObjectIdentifier(han.self)) // 打印 对象实例