UIApplication+UIWindow.swift 638 B

123456789101112131415161718192021222324
  1. //
  2. // UIApplication+UIWindow.swift
  3. // SKPhotoBrowser
  4. //
  5. // Created by Josef Dolezal on 25/09/2017.
  6. // Copyright © 2017 suzuki_keishi. All rights reserved.
  7. //
  8. import Foundation
  9. internal extension UIApplication {
  10. var preferredApplicationWindow: UIWindow? {
  11. // Since delegate window is of type UIWindow??, we have to
  12. // unwrap it twice to be sure the window is not nil
  13. if let appWindow = UIApplication.shared.delegate?.window, let window = appWindow {
  14. return window
  15. } else if let window = UIApplication.shared.keyWindow {
  16. return window
  17. }
  18. return nil
  19. }
  20. }