Skip to content

Instantly share code, notes, and snippets.

@wadva474
Created August 13, 2023 22:02
Show Gist options
  • Save wadva474/1d8bc14093146937140de59877766168 to your computer and use it in GitHub Desktop.
Save wadva474/1d8bc14093146937140de59877766168 to your computer and use it in GitHub Desktop.
import Foundation
import shared
final class Koin {
private var core: Koin_coreKoin?
static let instance = Koin()
static func start() {
if instance.core == nil {
let app = KoinIOS.shared.initialize()
instance.core = app.koin
}
if instance.core == nil {
fatalError("Can't initialize Koin.")
}
}
private init() {
}
func get<T: AnyObject>() -> T {
guard let core = core else {
fatalError("You should call `start()` before using \(#function)")
}
guard let result = core.get(objCClass: T.self) as? T else {
fatalError("Koin can't provide an instance of type: \(T.self)")
}
return result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment