Created
April 17, 2020 23:29
-
-
Save FitzAfful/58eb2b0f6cf5e46fbee2ecab8507c02b to your computer and use it in GitHub Desktop.
Observable is a generic class that helps you to bind your ViewModel to your View Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Observable<T> { | |
var value: T { | |
didSet { | |
listener?(value) | |
} | |
} | |
private var listener: ((T) -> Void)? | |
init(_ value: T) { | |
self.value = value | |
} | |
func bind(_ closure: @escaping (T) -> Void) { | |
closure(value) | |
listener = closure | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment