I see the potential use willSetand didSetreplacement parts KVO type of code that I have used in Objective-C. One of the benefits of Objective-C is dynamism, especially the ability to create runtime behavior. To willSetand didSetwere helpful to me, I need to be able to dynamically assign their behavior. Is it possible to establish their "content" or the behavior that they embody dynamically? One use case would be to attach model properties 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
})
}
}
source
share