Skip to content

Instantly share code, notes, and snippets.

@V8tr
Last active August 3, 2018 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save V8tr/402f4663e34bd4810274e33e3a7e05ad to your computer and use it in GitHub Desktop.
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
// 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