Skip to content

Instantly share code, notes, and snippets.

@FitzAfful
Created April 17, 2020 23:29
Show Gist options
  • Save FitzAfful/58eb2b0f6cf5e46fbee2ecab8507c02b to your computer and use it in GitHub Desktop.
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
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