Skip to content

Instantly share code, notes, and snippets.

View ivanopcode's full-sized avatar

Ivan ivanopcode

View GitHub Profile
@ivanopcode
ivanopcode / measure
Created June 20, 2023 19:50
Convince wrapper for measuring function execution time, relies on Darwin's Foundation
// MIT
// Alexey Grigorev, Ivan Oparin
import Foundation
@discardableResult
public func measure(_ action: () -> ()) -> Double {
let start = Date()
action()
let end = Date()
@ivanopcode
ivanopcode / configureIoC
Created June 20, 2023 19:48
IoC initialization function for SwiftUI-lifecycle based apps
// MIT
// Alexey Grigorev, Ivan Oparin
@MainActor
static private func configureIoC() {
ObjectFactory.initialize(with: DIContainerBuilder.container)
}
@ivanopcode
ivanopcode / DIContainerBuilder.swift
Created June 20, 2023 19:42
Swinject-based DI container builder template
// MIT
// by Alexey Grigorev, Ivan Oparin
import Swinject
class DIContainerBuilder {
public static func build() -> Container {
let container = Container()
return container
@ivanopcode
ivanopcode / NetworkStatusService
Created June 20, 2023 19:35
Thread-Safe Network Status Monitor using Swift Actors and Combine
// MIT
// by Alexey Grigorev, Ivan Oparin
// A thread-safe service for subscribing to network status updates on Apple's platforms. It
// utilizes Apple's Network framework to monitor network conditions. The service
// uses the actor model for thread safety, protecting from data
// races. Updates are emitted via Combine publishers, for easy integration with
// reactive or async code. Updates include network connection status, if the
// connection is expensive, and if the status has changed."