Skip to content

Instantly share code, notes, and snippets.

@netbe
Created June 5, 2015 16:43
Show Gist options
  • Save netbe/552a0c7ee52a4869c5ba to your computer and use it in GitHub Desktop.
Save netbe/552a0c7ee52a4869c5ba to your computer and use it in GitHub Desktop.
Solution to disable AppDelegate code in swift
import Foundation
import UIKit
func isRunningTests() -> Bool {
let environment = NSProcessInfo.processInfo().environment
if let injectBundle = environment["XCInjectBundle"] as? NSString {
return injectBundle.pathExtension == "xctest"
}
return false
}
class UnitTestsAppDelegate: UIResponder, UIApplicationDelegate
{
}
if isRunningTests() {
UIApplicationMain(Process.argc, Process.unsafeArgv, NSStringFromClass(UIApplication), NSStringFromClass(UnitTestsAppDelegate))
}else{
UIApplicationMain(Process.argc, Process.unsafeArgv, NSStringFromClass(UIApplication), NSStringFromClass(AppDelegate))
}
@DivineDominion
Copy link

This should work:

let isRunningTests =  ProcessInfo.processInfo
    .environment["XCTestConfigurationFilePath"] != nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment