Last active
August 3, 2018 08:58
-
-
Save V8tr/402f4663e34bd4810274e33e3a7e05ad to your computer and use it in GitHub Desktop.
Refactoring Massive App Delegate using Command pattern. See blog post for more details: https://www.vadimbulavin.com/refactoring-massive-app-delegate
This file contains hidden or 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
// MARK: - Builder | |
final class StartupCommandsBuilder { | |
private var window: UIWindow! | |
func setKeyWindow(_ window: UIWindow) -> StartupCommandsBuilder { | |
self.window = window | |
return self | |
} | |
func build() -> [Command] { | |
return [ | |
InitializeThirdPartiesCommand(), | |
InitialViewControllerCommand(keyWindow: window), | |
InitializeAppearanceCommand(), | |
RegisterToRemoteNotificationsCommand() | |
] | |
} | |
} | |
// MARK: - App Delegate | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
StartupCommandsBuilder() | |
.setKeyWindow(window!) | |
.build() | |
.forEach { $0.execute() } | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment