Skip to content

Instantly share code, notes, and snippets.

View johnclayton's full-sized avatar

John Clayton johnclayton

View GitHub Profile
import Foundation
extension UserDefaults {
struct Key {
typealias RawValue = String
let rawValue: RawValue
init(_ string: String) {
self.rawValue = string
}
@johnclayton
johnclayton / ImageLoader.swift
Created April 1, 2022 17:01
Closure based image loader
import UIKit
import Combine
final class ImageLoader {
typealias LoadPublisher = AnyPublisher<UIImage, Error>
typealias Cache = NSCache<CacheKey, UIImage>
private let loadImage: (URL, Cache) -> LoadPublisher
private let cachedImage: (URL, Cache) -> UIImage?