Swift 中获取对象类型

Objective-C风格获取对象类型:

let date = NSDate()
let name: AnyClass! = object_getClass(date)
debugPrint(name) // __NSDate

Swift 风格获取对象类型:

let date1 = NSDate()
let name1 = type(of: date)
debugPrint(name1) // __NSDate

let str = "hello"
let name2 = type(of: str)
debugPrint(name2) // Swift.String

你可能感兴趣的:(Swift 中获取对象类型)