Skip to content

Instantly share code, notes, and snippets.

@V8tr
Last active August 3, 2018 08:04
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/0bfa78ea06aa522b0b5e72328d83d4fc to your computer and use it in GitHub Desktop.
Save V8tr/0bfa78ea06aa522b0b5e72328d83d4fc to your computer and use it in GitHub Desktop.
Refactoring Massive App Delegate using Composite pattern. See blog post for more details: https://www.vadimbulavin.com/refactoring-massive-app-delegate
enum AppDelegateFactory {
static func makeDefault() -> AppDelegateType {
return CompositeAppDelegate(appDelegates: [PushNotificationsAppDelegate(), StartupConfiguratorAppDelegate(), ThirdPartiesConfiguratorAppDelegate()])
}
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let appDelegate = AppDelegateFactory.makeDefault()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
_ = appDelegate.application?(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
appDelegate.application?(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment