Skip to content

Instantly share code, notes, and snippets.

@dani-mp
Last active August 29, 2015 14:21
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 dani-mp/fdb81a8e28c1b414b85d to your computer and use it in GitHub Desktop.
Save dani-mp/fdb81a8e28c1b414b85d to your computer and use it in GitHub Desktop.
AppDelegate to run unit tests faster in Swift.
1. Comment out @UIApplicationMain in your AppDelegate.
2. Create main.swift file with the following code:
import Foundation
import UIKit
let isRunningTests = NSClassFromString("XCTestCase") != nil
if isRunningTests {
UIApplicationMain(Process.argc, Process.unsafeArgv, nil, NSStringFromClass(TestingAppDelegate))
} else {
UIApplicationMain(Process.argc, Process.unsafeArgv, nil, NSStringFromClass(AppDelegate))
}
3. Create TestingAppDelegate.swift with the following code:
import UIKit
class TestingAppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
}
4. In your AppDelegate, create the window, assign its root view controller and make it key and visible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment