-
Notifications
You must be signed in to change notification settings - Fork 45
/
main.swift
47 lines (38 loc) · 1.27 KB
/
main.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import Foundation
import UIKit
/// Custom main.swift to prevent app execution in the unit test.
/// Overwrites the app delegate with an empty implementation.
private let argc = CommandLine.argc
private let argv = UnsafeMutableRawPointer(CommandLine.unsafeArgv)
.bindMemory(
to: UnsafeMutablePointer<Int8>?.self,
capacity: Int(CommandLine.argc)
)
// Could also be `nil` after the documentation
private let principalClassName = NSStringFromClass(UIApplication.self)
#if DEBUG
extension ProcessInfo {
private var isRunningTests: Bool {
return arguments.contains("IS_RUNNING_TESTS")
}
/// Returns the proper app delegate type for the debug configuration
public var appDelegateType: UIApplicationDelegate.Type {
let appDelegateType: UIApplicationDelegate.Type = isRunningTests ?
TestAppDelegate.self :
AppDelegate.self
return appDelegateType
}
}
/// App delegate for the unit tests
final class TestAppDelegate: UIResponder, UIApplicationDelegate {
}
private let delegateClassName = NSStringFromClass(ProcessInfo.processInfo.appDelegateType)
#else
private let delegateClassName = NSStringFromClass(AppDelegate.self)
#endif
_ = UIApplicationMain(
argc,
argv,
principalClassName,
delegateClassName
)