它们之间的区别是什么?你能举个例子说明我应该使用dynamic / mutable / any / constants属性吗?
答案 0 :(得分:7)
您的所有答案都在此链接中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)
}