Created
August 21, 2021 09:47
-
-
Save Shubham0812/c51ae0b5ddb5ca3a19bd4c5aa50b5948 to your computer and use it in GitHub Desktop.
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
import Foundation | |
class Box<T> { | |
typealias Listener = (T) -> () | |
// MARK:- variables | |
var value: T { | |
didSet { | |
listener?(value) | |
} | |
} | |
var listener: Listener? | |
// MARK:- inits | |
init(_ value: T) { | |
self.value = value | |
} | |
// MARK:- functions | |
func bind(listener: Listener?) { | |
self.listener = listener | |
} | |
func removeBinding() { | |
self.listener = nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment