This file contains hidden or 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
enum AppDelegateFactory { | |
static func makeDefault() -> AppDelegateType { | |
return CompositeAppDelegate(appDelegates: [PushNotificationsAppDelegate(), StartupConfiguratorAppDelegate(), ThirdPartiesConfiguratorAppDelegate()]) | |
} | |
} | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? |
This file contains hidden or 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
class PushNotificationsAppDelegate: AppDelegateType { | |
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { | |
// Registered successfully | |
} | |
} | |
class StartupConfiguratorAppDelegate: AppDelegateType { | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
// Perform startup configurations, e.g. build UI stack, setup UIApperance | |
return true |
This file contains hidden or 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
typealias AppDelegateType = UIResponder & UIApplicationDelegate | |
class CompositeAppDelegate: AppDelegateType { | |
private let appDelegates: [AppDelegateType] | |
init(appDelegates: [AppDelegateType]) { | |
self.appDelegates = appDelegates | |
} | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { |
This file contains hidden or 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
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
let mediator = AppLifecycleMediator.makeDefaultMediator() | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
return true | |
} | |
} |
This file contains hidden or 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
// MARK: - AppLifecycleListener | |
protocol AppLifecycleListener { | |
func onAppWillEnterForeground() | |
func onAppDidEnterBackground() | |
func onAppDidFinishLaunching() | |
} | |
// MARK: - Mediator |
This file contains hidden or 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
// MARK: - Builder | |
final class StartupCommandsBuilder { | |
private var window: UIWindow! | |
func setKeyWindow(_ window: UIWindow) -> StartupCommandsBuilder { | |
self.window = window | |
return self | |
} |
This file contains hidden or 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
protocol Command { | |
func execute() | |
} | |
struct InitializeThirdPartiesCommand: Command { | |
func execute() { | |
// Third parties are initialized here | |
} | |
} |
This file contains hidden or 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
func averageBenchmark(iterations: Int, numberOfAttempts: Int, block: (Int) -> Void) -> TimeInterval { | |
var accumulatedResult: TimeInterval = 0 | |
for _ in 0..<numberOfAttempts { | |
let result = benchmark { | |
for i in 0..<iterations { | |
block(i) | |
} | |
} | |
accumulatedResult += result |
This file contains hidden or 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
func benchmark(block: () -> Void) -> TimeInterval { | |
let startTime = CFAbsoluteTimeGetCurrent() | |
block() | |
let endTime = CFAbsoluteTimeGetCurrent() | |
let totalTime = endTime - startTime | |
return totalTime | |
} |
This file contains hidden or 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
final class ReadWriteLock { | |
private var rwlock: pthread_rwlock_t = { | |
var rwlock = pthread_rwlock_t() | |
pthread_rwlock_init(&rwlock, nil) | |
return rwlock | |
}() | |
func writeLock() { | |
pthread_rwlock_wrlock(&rwlock) | |
} |