I see potential for use of willSet
& didSet
to replace parts of KVO-type code I'd use in Objective-C. One of the benefits of Objective-C is it's dynamism, specially the ability to create behavior at runtime. In order for willSet
& didSet
to be useful for me, I need to be able to dynamically assign their behavior. Is it possible to set their "contents" or the behavior they embody dynamically? One use case would be to bind properties of a model to a view. In pseudo-code:
mvvm = new MVVM(packageModel, 'url', packageView, 'urlLabel')
class MVVM {
init(model: Model, modelPropertyName : NSString, view: View, viewPropertyName : NSString) {
model.propertyDescriptor('willSet', modelPropertyName, (newUrl){
view[viewPropertyName].text = newUrl
})
}
}