DispatchQueue+Extensions.swift 486 B

123456789101112131415161718192021
  1. //
  2. // DispatchQueue+Extensions.swift
  3. // Platform
  4. //
  5. // Created by Krunoslav Zaher on 10/22/16.
  6. // Copyright © 2016 Krunoslav Zaher. All rights reserved.
  7. //
  8. import Dispatch
  9. extension DispatchQueue {
  10. private static var token: DispatchSpecificKey<()> = {
  11. let key = DispatchSpecificKey<()>()
  12. DispatchQueue.main.setSpecific(key: key, value: ())
  13. return key
  14. }()
  15. static var isMain: Bool {
  16. DispatchQueue.getSpecific(key: token) != nil
  17. }
  18. }