Commit 38ff84be by ConfusedVorlon Committed by GitHub

Support extensions (#1)

Use an extension safe Application.shared
parent 6dc1048c
......@@ -31,9 +31,20 @@
import UIKit
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.
public static var keyWindow: UIWindow? {
return UIApplication.shared.keyWindow
return Application.shared.keyWindow
}
/// An optional reference to the top most view controller.
......@@ -43,7 +54,7 @@ public struct Application {
/// A boolean indicating if the device is in Landscape mode.
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.
......@@ -53,26 +64,26 @@ public struct Application {
/// The current UIInterfaceOrientation value.
public static var orientation: UIInterfaceOrientation {
return UIApplication.shared.statusBarOrientation
return Application.shared.statusBarOrientation
}
/// Retrieves the device status bar style.
public static var statusBarStyle: UIStatusBarStyle {
get {
return UIApplication.shared.statusBarStyle
return Application.shared.statusBarStyle
}
set(value) {
UIApplication.shared.statusBarStyle = value
Application.shared.statusBarStyle = value
}
}
/// Retrieves the device status bar hidden state.
public static var isStatusBarHidden: Bool {
get {
return UIApplication.shared.isStatusBarHidden
return Application.shared.isStatusBarHidden
}
set(value) {
UIApplication.shared.isStatusBarHidden = value
Application.shared.isStatusBarHidden = value
}
}
......@@ -86,6 +97,6 @@ public struct Application {
/// A reference to the user interface layout direction.
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