-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheSpriteManager.swift
More file actions
37 lines (31 loc) · 953 Bytes
/
CacheSpriteManager.swift
File metadata and controls
37 lines (31 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// CacheSpriteManager.swift
// Swothie
//
// Created by Passavee Losripat on 22/2/2567 BE.
//
import Foundation
import SwiftUI
class ImageCache {
static let shared = ImageCache()
private init() {}
var cache: [String: UIImage] = [:]
func getImage(forKey key: String) -> UIImage? {
return cache[key]
}
func setImage(_ image: UIImage, forKey key: String) {
cache[key] = image
}
@MainActor func preloadImages() {
let allFruit: [String] = ["Avocado", "Peach", "Mango"]
for data in otData{
for fruit in allFruit {
let key:String = fruit + data.message
let newImage = ImageRenderer(content: PlantTowerEnemyView(sign: data, imageName: fruit))
if let imageForCache = newImage.uiImage{
ImageCache.shared.setImage(imageForCache, forKey: key)
}
}
}
}
}