Skip to content

Instantly share code, notes, and snippets.

@emoonadev
emoonadev / CoreDependency.swift
Last active March 3, 2023 21:19
Super simple IOC pattern using property wrapper
import SwiftUI
protocol Resolver {
func resolve<T>() -> T
func resolve<T>(_ type: T.Type) -> T
}
struct DependencyInjector {
enum InstanceType {
@emoonadev
emoonadev / CoreDependency.kt
Created July 27, 2020 14:56
Super simple dependency injection
import kotlin.reflect.KProperty
typealias DependencyContainer = (factory: Container) -> Unit
interface Resolver {
fun <T> resolve(type: Class<T>): T
fun init(apply: DependencyContainer)
}
inline fun <reified T> Resolver.resolve() = resolve(T::class.java)
@emoonadev
emoonadev / KeychainStorage.swift
Created November 5, 2021 08:49
KeychainStorage
typealias KeychainDictionary = [String: Any]
@propertyWrapper
class KeychainStorage<Model: Codable> {
let key: String
let kClass: KClass
let logHandler: (String) -> ()
var projectedValue: KeychainStorage { self }
@emoonadev
emoonadev / TableViewDataSourceProvider.swift
Last active November 16, 2021 14:31
TableViewDataSourceProvider
protocol ObservableSearchBar {
var textDidChange: Observable<String> { get }
var text: String? { get set }
}
class TableViewDataSourceProvider<Item, Cell: UITableViewCell & NibLoadableView>: NSObject, UITableViewDataSource, UITableViewDelegate, UISearchResultsUpdating {
typealias CellConfigurator = (_ indexPath: IndexPath, _ item: Item, _ cell: Cell) -> Void
typealias HeightConfigurator = (_ indexPath: IndexPath, _ item: Item) -> CGFloat
typealias ContextMenuConfigurator = (_ indexPath: IndexPath, _ item: Item) -> UIMenu