From the course: iOS Development: Architecture
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Implementing one-way binding, part 1
From the course: iOS Development: Architecture
Implementing one-way binding, part 1
- [Narrator] In the following demo, I'm going to show you a way to implement one-way binding from the model view to the view. So let's get started. I've gone ahead and made some changes to the MVP demo. I renamed the presenter class and all its instances to ViewModel. Swift doesn't provide an out-of-the-box solution for property binding, so we'll introduce a (mumble) class. I'll add a new Swift source file called Binding. The (mumble) class is called Observable. I'm going to make it generic, so that it can store any type. It has a property called Value. I set up the didSet property observer to get notified whenever the value changes. We'll also need the bind property. The bind property is a closure. I assign an empty closure as default value. We call the bind closure and test the value whenever didSet gets involved. We also need an initializer. The value argument is the observed object. So this is the Observable class. Next, we're going to refactor the ViewModel class.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Introduction to fundamental architectural design patterns57s
-
(Locked)
The model-view-controller3m 50s
-
(Locked)
The model-view-presenter1m 22s
-
(Locked)
MVP example2m 41s
-
(Locked)
Refactoring to MVP: Model2m 26s
-
(Locked)
Refactoring to MVP: Presenter2m 32s
-
(Locked)
Refactoring to MVP: View controller4m 29s
-
(Locked)
The Model-View-ViewModel pattern1m 15s
-
(Locked)
Implementing one-way binding, part 11m 34s
-
(Locked)
Implementing one-way binding, part 23m 55s
-
-
-
-
-
-
-