Skip to content

Instantly share code, notes, and snippets.

@jaylyerly
Created April 6, 2017 21:20
Show Gist options
  • Save jaylyerly/1ffedf1334be60df5091399e489553e0 to your computer and use it in GitHub Desktop.
Save jaylyerly/1ffedf1334be60df5091399e489553e0 to your computer and use it in GitHub Desktop.
This implementation of main.swift for an iOS app dynamically switch the AppDelegate at runtime based on the presence of the TestingAppDelegate class, which is only available during unit testing.
import Foundation
import UIKit
let appDelegateClass: AnyClass = NSClassFromString("AppNameTests.TestingAppDelegate") ?? AppDelegate.self
UIApplicationMain(Process.argc, Process.unsafeArgv, nil, NSStringFromClass(appDelegateClass))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment