swift中获取对象的结构类型

2017-03-20  本文已影响8人  zhouwude
struct Person {
    let name: String
    let age: Int
}

let xiaoMing = Person(name: "XiaoMing", age: 16)
let r = Mirror(reflecting: xiaoMing) 

print("xiaoMing 是 \(r.displayStyle!)")
//输出-   xiaoMing 是 struct
// displayStyle是一个枚举里面包含了 一些类型
public enum DisplayStyle {

        case `struct`

        case `class`

        case `enum`

        case tuple

        case optional

        case collection

        case dictionary

        case set
    }


上一篇 下一篇

猜你喜欢

热点阅读