Last active
October 31, 2019 07:08
-
-
Save JonFir/614b70c93c0cdce7580950019c405040 to your computer and use it in GitHub Desktop.
UsselesRefactoring#1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 0. Default. Xcode generating. | |
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var window: UIWindow? | |
func scene( | |
_ scene: UIScene, | |
willConnectTo session: UISceneSession, | |
options connectionOptions: UIScene.ConnectionOptions) { | |
let contentView = ContentView() | |
if let windowScene = scene as? UIWindowScene { | |
let window = UIWindow(windowScene: windowScene) | |
window.rootViewController = UIHostingController(rootView: contentView) | |
self.window = window | |
window.makeKeyAndVisible() | |
} | |
} | |
} | |
// 1. Reducing nesting. Grouping data. | |
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var window: UIWindow? | |
func scene( | |
_ scene: UIScene, | |
willConnectTo session: UISceneSession, | |
options connectionOptions: UIScene.ConnectionOptions) { | |
guard let windowScene = scene as? UIWindowScene else { return } | |
let window = UIWindow(windowScene: windowScene) | |
window.rootViewController = UIHostingController(rootView: ContentView()) | |
self.window = window | |
window.makeKeyAndVisible() | |
} | |
} | |
// 2. Remembering what swift is functional language | |
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var window: UIWindow? | |
func scene( | |
_ scene: UIScene, | |
willConnectTo session: UISceneSession, | |
options connectionOptions: UIScene.ConnectionOptions) { | |
window = (scene as? UIWindowScene).map(UIWindow.init) | |
window?.rootViewController = UIHostingController(rootView: ContentView()) | |
window?.makeKeyAndVisible() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment