Sitemap
Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

MVVM — Bind views

3 min readMay 19, 2021

--

Photo by Greg Rosenke on Unsplash
For further details on how MVVM works, here’s a nice post [link]
class ViewModel {

var onPersonChanged: ((Person) -> Void)?

func fetchPosts() {
// these values are hard-coded. Not relevant(to this post)
// where this data is coming from.
let person = Person(id: 1, name: "Cristhian", age: 26)
onPersonChanged?(person)
}
}
private func addObservers() {
viewModel.personName.bind { [weak self] name in
self?.nameLabel.text = name
}

viewModel.personAge.bind { [weak self] age in
self?.ageLabel.text = "\(age)"
}
}

--

--

Nerd For Tech
Nerd For Tech

Published in Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Cristhian Leon
Cristhian Leon

Written by Cristhian Leon

Professional iOS Developer with a passion for building performant, elegant apps — Golang enthusiast.

No responses yet