Created
June 5, 2015 16:43
-
-
Save netbe/552a0c7ee52a4869c5ba to your computer and use it in GitHub Desktop.
Solution to disable AppDelegate code in swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
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
Not working in Swift 3.
UIApplicationMain calls need to be like this:
UIApplicationMain(Process.argc, UnsafeMutablePointer<UnsafeMutablePointer<CChar>>(Process.unsafeArgv), NSStringFromClass(UIApplication.self), NSStringFromClass(UnitTestsAppDelegate.self))
Source: here
Also isRunningTests is not working under Swift 3.