File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -105,7 +105,11 @@ public struct CachedAsyncImage<Content>: View where Content: View {
105105 /// would name with the `@2x` suffix if stored in a file on disk.
106106 public init ( url: URL ? , urlCache: URLCache = . shared, scale: CGFloat = 1 ) where Content == Image {
107107 self . init ( url: url, urlCache: urlCache, scale: scale) { phase in
108+ #if os(macOS)
109+ phase. image ?? Image ( nsImage: . init( ) )
110+ #else
108111 phase. image ?? Image ( uiImage: . init( ) )
112+ #endif
109113 }
110114 }
111115
@@ -201,10 +205,17 @@ public struct CachedAsyncImage<Content>: View where Content: View {
201205 guard let url = url else { return }
202206 let request = URLRequest ( url: url)
203207 let ( data, _) = try await urlSession. data ( for: request)
208+ #if os(macOS)
209+ if let nsImage = NSImage ( data: data) {
210+ let image = Image ( nsImage: nsImage)
211+ phase = . success( image)
212+ }
213+ #else
204214 if let uiImage = UIImage ( data: data) {
205215 let image = Image ( uiImage: uiImage)
206216 phase = . success( image)
207217 }
218+ #endif
208219 } catch {
209220 phase = . failure( error)
210221 }
You can’t perform that action at this time.
0 commit comments