From 1e7c0534fc6a3d352bbe5763e687059cd342c025 Mon Sep 17 00:00:00 2001 From: Abdullah Selek Date: Wed, 12 Feb 2020 19:02:33 +0000 Subject: [PATCH] Use keyPath to read UIApplication.shared. (#81) --- .../PanModalPresentable+LayoutHelpers.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift b/PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift index 2437ffa..5775e0c 100644 --- a/PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift +++ b/PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift @@ -27,7 +27,10 @@ extension PanModalPresentable where Self: UIViewController { Gives us the safe area inset from the top. */ var topLayoutOffset: CGFloat { - return UIApplication.shared.keyWindow?.rootViewController?.topLayoutGuide.length ?? 0 + guard let application = UIApplication.value(forKeyPath: #keyPath(UIApplication.shared)) as? UIApplication else { + return 0 + } + return application.keyWindow?.rootViewController?.topLayoutGuide.length ?? 0 } /** @@ -35,7 +38,10 @@ extension PanModalPresentable where Self: UIViewController { Gives us the safe area inset from the bottom. */ var bottomLayoutOffset: CGFloat { - return UIApplication.shared.keyWindow?.rootViewController?.bottomLayoutGuide.length ?? 0 + guard let application = UIApplication.value(forKeyPath: #keyPath(UIApplication.shared)) as? UIApplication else { + return 0 + } + return application.keyWindow?.rootViewController?.bottomLayoutGuide.length ?? 0 } /**