SimpleTwoWayBindingIOS
SimpleTwoWayBindingIOS copied to clipboard
Where is the model?
In your examples i see only a viewModel with all properties... how can i declare a model class in view model and be able to bind their properties?
class PersonModel {
var name: String?
var surname: String?
}
class PersonViewModel {
var person:Person!
var completeName{
return person.name + " " + person.surname
}
}
class ViewController: UIViewController {
.
.
.
var personViewModel:PersonViewModel!
.
.
.
personViewModel.completeName = personCompleteNameTextField.text // ???
}
How can i bind (change) per model (Person) name or surname from viewModel?
Hello @fabiosoft, A model in MVVM is a domain object ( or a data access layer ) which takes care of persistence or retrieval of data. In the above case, PersonModel as a domain object would implement a save and a get method which PersonViewModel can use. One should be vary at what time do we commit the save as per change might be memory/network intensive