美文网首页
swift中获取对象的结构类型

swift中获取对象的结构类型

作者: zhouwude | 来源:发表于2017-03-20 15:58 被阅读8次
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
    }


相关文章

网友评论

      本文标题:swift中获取对象的结构类型

      本文链接:https://www.haomeiwen.com/subject/riqinttx.html