[英]DynamicProperty vs MutableProperty vs AnyProperty vs ConstantsProperty
What's difference between them? 他们之间有什么区别? Could you give me an example of in which scenario I should use dynamic/mutable/any/constants property?
你能举个例子说明我应该使用dynamic / mutable / any / constants属性吗?
All your answer are in this link Property.swift 你的所有答案都在这个链接Property.swift
I give you some examples: 我举几个例子:
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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.