Skip to content

Instantly share code, notes, and snippets.

@emoonadev
emoonadev / TableViewDataSourceProvider.swift
Last active November 16, 2021 14:31
TableViewDataSourceProvider
View TableViewDataSourceProvider.swift
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
@emoonadev
emoonadev / KeychainStorage.swift
Created November 5, 2021 08:49
KeychainStorage
View KeychainStorage.swift
typealias KeychainDictionary = [String: Any]
@propertyWrapper
class KeychainStorage<Model: Codable> {
let key: String
let kClass: KClass
let logHandler: (String) -> ()
var projectedValue: KeychainStorage { self }
@emoonadev
emoonadev / CoreDependency.kt
Created July 27, 2020 14:56
Super simple dependency injection
View CoreDependency.kt
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 / CoreDependency.swift
Last active November 5, 2021 08:51
Super simple IOC pattern using property wrapper
View CoreDependency.swift
import SwiftUI
protocol Resolver {
func resolve<T>() -> T
func resolve<T>(_ type: T.Type) -> T
}
struct DependencyInjector {
enum InstanceType {