Swift:检测属性是变量还是常量

时间:2016-04-18 13:26:49

标签: swift properties mirror

我正在尝试查找哪个属性为vars,哪些属于let

使用镜像我可以得到一个对象Child,我可以从中获取标签,值的值和动态类型

    let mirrored_object = Mirror(reflecting: myObject)
    for property in mirrored_object.children {

        // Here I have property as Child
        // from which I can get 
        // property.label
        // property.value
        // property.value.dynamicType
    }

但这是dynamicType,我的意思是......

    let myProperty: String? <--- Will return an optional
    let myProperty: String   <--- Will return .Some

但我想要检测的是:

    var myProperty: String

VS

    let myProperty: String

0 个答案:

没有答案