2016-01-09 280 views

回答

5

所有的答案都在這個環節Property.swift

我給你一些例子:

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

    print(observableProperty) 

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

    // Thread safe observable mutable property. It's value is changable 
    let mutableProperty = MutableProperty<String>("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) 
    } 
相關問題