Skip to content

Instantly share code, notes, and snippets.

@Shubham0812
Created August 21, 2021 09:47
Show Gist options
  • Save Shubham0812/c51ae0b5ddb5ca3a19bd4c5aa50b5948 to your computer and use it in GitHub Desktop.
Save Shubham0812/c51ae0b5ddb5ca3a19bd4c5aa50b5948 to your computer and use it in GitHub Desktop.
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