This repository was archived by the owner on Mar 7, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import SwiftUI
2+
3+ final class ImageCache {
4+ static let shared = ImageCache ( )
5+ private var cache = NSCache < NSURL , UIImage > ( )
6+
7+ private init ( ) { }
8+
9+ // Store UIImage
10+ func set( _ image: UIImage , for url: URL ) {
11+ cache. setObject ( image, forKey: url as NSURL )
12+ }
13+
14+ // Retrieve as SwiftUI Image
15+ func get( for url: URL ) -> Image ? {
16+ if let uiImage = cache. object ( forKey: url as NSURL ) {
17+ return Image ( uiImage: uiImage)
18+ }
19+ return nil
20+ }
21+ }
Original file line number Diff line number Diff line change @@ -207,7 +207,9 @@ private struct AppRowView: View {
207207 . clipShape ( RoundedRectangle ( cornerRadius: 10 ) )
208208 . shadow ( radius: 1 , y: 1 )
209209 . onAppear {
210- ImageCache . shared. set ( image, for: iconURL)
210+ if let uiImage = image. asUIImage ( ) {
211+ ImageCache . shared. set ( uiImage, for: iconURL)
212+ }
211213 }
212214 case . failure:
213215 Image ( systemName: " app " )
You can’t perform that action at this time.
0 commit comments