Impressia/Vernissage/Services/CacheAvatarService.swift
2023-01-05 21:08:19 +01:00

27 lines
598 B
Swift

//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
import Foundation
import SwiftUI
public class CacheAvatarService {
public static let shared = CacheAvatarService()
private init() { }
private var cache: Dictionary<String, UIImage> = [:]
func addImage(for id: String, data: Data) {
if let uiImage = UIImage(data: data) {
self.cache[id] = uiImage
}
}
func getImage(for id: String) -> UIImage? {
return self.cache[id]
}
}