Skip to content

Instantly share code, notes, and snippets.

@AndresR173
Created June 1, 2021 21:48
Show Gist options
  • Save AndresR173/8547f07349c3390850cbdff85c88003c to your computer and use it in GitHub Desktop.
Save AndresR173/8547f07349c3390850cbdff85c88003c to your computer and use it in GitHub Desktop.
Boxing Technique
import Foundation
final class Box<T> {
typealias Listener = (T) -> Void
var listener: Listener?
var value: T {
didSet {
listener?(value)
}
}
init(_ value: T) {
self.value = value
}
func bind(listener: Listener?) {
self.listener = listener
listener?(value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment