You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
512 B

6 years ago
  1. //
  2. // DataBox.swift
  3. // GMERemittance
  4. //
  5. // Created by Sujal on 12/8/17.
  6. // Copyright © 2017 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. class Box<T> {
  10. typealias Listener = (T) -> Void
  11. var listener: Listener?
  12. var value: T {
  13. didSet {
  14. listener? (value)
  15. }
  16. }
  17. init(_ value: T) {
  18. self.value = value
  19. }
  20. func bind(listener: Listener?) {
  21. self.listener = listener
  22. listener? (value)
  23. }
  24. }