Commit 38ff84be by ConfusedVorlon Committed by GitHub

Support extensions (#1)

Use an extension safe Application.shared
parent 6dc1048c
...@@ -31,9 +31,20 @@ ...@@ -31,9 +31,20 @@
import UIKit import UIKit
public struct Application { public struct Application {
public static var shared: UIApplication {
let sharedSelector = NSSelectorFromString("sharedApplication")
guard UIApplication.responds(to: sharedSelector) else {
fatalError("[Material: Extensions cannot access Application]")
}
let shared = UIApplication.perform(sharedSelector)
return shared?.takeUnretainedValue() as! UIApplication
}
/// An optional reference to the main UIWindow. /// An optional reference to the main UIWindow.
public static var keyWindow: UIWindow? { public static var keyWindow: UIWindow? {
return UIApplication.shared.keyWindow return Application.shared.keyWindow
} }
/// An optional reference to the top most view controller. /// An optional reference to the top most view controller.
...@@ -43,7 +54,7 @@ public struct Application { ...@@ -43,7 +54,7 @@ public struct Application {
/// A boolean indicating if the device is in Landscape mode. /// A boolean indicating if the device is in Landscape mode.
public static var isLandscape: Bool { public static var isLandscape: Bool {
return UIApplication.shared.statusBarOrientation.isLandscape return Application.shared.statusBarOrientation.isLandscape
} }
/// A boolean indicating if the device is in Portrait mode. /// A boolean indicating if the device is in Portrait mode.
...@@ -53,26 +64,26 @@ public struct Application { ...@@ -53,26 +64,26 @@ public struct Application {
/// The current UIInterfaceOrientation value. /// The current UIInterfaceOrientation value.
public static var orientation: UIInterfaceOrientation { public static var orientation: UIInterfaceOrientation {
return UIApplication.shared.statusBarOrientation return Application.shared.statusBarOrientation
} }
/// Retrieves the device status bar style. /// Retrieves the device status bar style.
public static var statusBarStyle: UIStatusBarStyle { public static var statusBarStyle: UIStatusBarStyle {
get { get {
return UIApplication.shared.statusBarStyle return Application.shared.statusBarStyle
} }
set(value) { set(value) {
UIApplication.shared.statusBarStyle = value Application.shared.statusBarStyle = value
} }
} }
/// Retrieves the device status bar hidden state. /// Retrieves the device status bar hidden state.
public static var isStatusBarHidden: Bool { public static var isStatusBarHidden: Bool {
get { get {
return UIApplication.shared.isStatusBarHidden return Application.shared.isStatusBarHidden
} }
set(value) { set(value) {
UIApplication.shared.isStatusBarHidden = value Application.shared.isStatusBarHidden = value
} }
} }
...@@ -86,6 +97,6 @@ public struct Application { ...@@ -86,6 +97,6 @@ public struct Application {
/// A reference to the user interface layout direction. /// A reference to the user interface layout direction.
public static var userInterfaceLayoutDirection: UIUserInterfaceLayoutDirection { public static var userInterfaceLayoutDirection: UIUserInterfaceLayoutDirection {
return UIApplication.shared.userInterfaceLayoutDirection return Application.shared.userInterfaceLayoutDirection
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment