let date = NSDate()
let date1 = Date()
// 获取任意 AnyObject! 并返回它的类型 AnyClass! , 参数为 nil, 返回值也为 nil
// 这个方法定义在 OC 的 runtime 中
let name: AnyClass! = object_getClass(date) // __NSDate
let name1: AnyClass! = object_getClass(date1) // __NSDate
// type(of:) 为 Swift 中的方法
let swiftName = type(of: date) // __NSDate
let swiftName1 = type(of: date1) // Date
print(name)
print(name1)
print(swiftName)
print(swiftName1)
let string = "Hello"
let nsString = "hello" as NSString
let stringName = type(of: string)
let nsStringName = type(of: string)
debugPrint(stringName) // Swift.String
debugPrint(nsStringName) // Swift.String
print(stringName) // String
print(nsStringName) // String
网友评论