Skip to content

Instantly share code, notes, and snippets.

@orgmir
Created August 21, 2018 02:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orgmir/553bae776bfdb0680a923c7003616377 to your computer and use it in GitHub Desktop.
Save orgmir/553bae776bfdb0680a923c7003616377 to your computer and use it in GitHub Desktop.
Disable the AppDelegate when initializing a NSApplication for testing
import AppKit
private func isTestRun() -> Bool {
return NSClassFromString("XCTestCase") != nil
}
if isTestRun() {
// This skipping setting up the app delegate
NSApplication.shared.run()
} else {
// For some magical reason, the AppDelegate is setup when
// initialized this way
_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment