Skip to content

Instantly share code, notes, and snippets.

@sundeepgupta
Created March 30, 2017 18:39
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 sundeepgupta/8a1c10406c0935edc66e16e57f612078 to your computer and use it in GitHub Desktop.
Save sundeepgupta/8a1c10406c0935edc66e16e57f612078 to your computer and use it in GitHub Desktop.
Dynamically swap AppDelegate at runtime for unit testing in Swift
let appDelegateClass: AnyClass? = NSClassFromString("TEST_TARGET_MODULE_NAME.TestAppDelegate") ?? AppDelegate.self
let classString = NSStringFromClass(appDelegateClass!)
let argv = UnsafeMutableRawPointer(CommandLine.unsafeArgv)
.bindMemory(to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc))
UIApplicationMain(CommandLine.argc, argv, nil, classString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment