当前位置:  开发笔记 > IOS > 正文

DynamicProperty vs MutableProperty vs AnyProperty vs ConstantsProperty

如何解决《DynamicPropertyvsMutablePropertyvsAnyPropertyvsConstantsProperty》经验,为你挑选了1个好方法。

他们之间有什么区别?你能举个例子说明我应该使用dynamic/mutable/any/constants属性吗?



1> Roman Derkac..:

你的所有答案都在这个链接Property.swift

我举几个例子:

let privatString = MutableProperty("PrivatString")
    // AnyProperty are only for observing. You can't change it with observableProperty.value
    let observableProperty: AnyProperty = AnyProperty(privatString)

    print(observableProperty)

    // ConstantProperty describes observable constant value.
    let constantProperty = ConstantProperty("ConstantString")
    //  constantProperty.value = "" Error

    // Thread safe observable mutable property. It's value is changable
    let mutableProperty = MutableProperty("mutableProperty")
    mutableProperty.value = "New mutable property value"

    // DynamicProperty uses KVO. 
    let dynamicProperty = DynamicProperty(object: self.view.layer, keyPath: "bounds")
    dynamicProperty.producer.startWithNext { frame in
        let frame = frame as! NSValue
        let rect = frame.CGRectValue()
        print(rect)
    }

推荐阅读
黄晓敏3023
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有