DeprecationWarner.swift 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // DeprecationWarner.swift
  3. // Platform
  4. //
  5. // Created by Shai Mishali on 1/9/18.
  6. // Copyright © 2018 Krunoslav Zaher. All rights reserved.
  7. //
  8. import Foundation
  9. #if DEBUG
  10. class DeprecationWarner {
  11. private static var warned = Set<Kind>()
  12. private static var _lock = NSRecursiveLock()
  13. static func warnIfNeeded(_ kind: Kind) {
  14. _lock.lock(); defer { _lock.unlock() }
  15. guard !warned.contains(kind) else { return }
  16. warned.insert(kind)
  17. print("ℹ️ [DEPRECATED] \(kind.message)")
  18. }
  19. }
  20. extension DeprecationWarner {
  21. enum Kind {
  22. case variable
  23. case globalTestFunctionNext
  24. case globalTestFunctionError
  25. case globalTestFunctionCompleted
  26. var message: String {
  27. switch self {
  28. case .variable: return "`Variable` is planned for future deprecation. Please consider `BehaviorRelay` as a replacement. Read more at: https://git.io/vNqvx"
  29. case .globalTestFunctionNext: return "The `next()` global function is planned for future deprecation. Please use `Recorded.next()` instead."
  30. case .globalTestFunctionError: return "The `error()` global function is planned for future deprecation. Please use `Recorded.error()` instead."
  31. case .globalTestFunctionCompleted: return "The `completed()` global function is planned for future deprecation. Please use `Recorded.completed()` instead."
  32. }
  33. }
  34. }
  35. }
  36. #endif