manishkkatoch / SimpleTwoWayBindingIOS

An ultra light, ultra simple two way binding library for IOS and Swift.
MIT License
165 stars 48 forks source link

Where is the model? #5

Open fabiosoft opened 6 years ago

fabiosoft commented 6 years ago

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?

manishkkatoch commented 6 years ago

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