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 {
105
105
/// would name with the `@2x` suffix if stored in a file on disk.
106
106
public init ( url: URL ? , urlCache: URLCache = . shared, scale: CGFloat = 1 ) where Content == Image {
107
107
self . init ( url: url, urlCache: urlCache, scale: scale) { phase in
108
+ #if os(macOS)
109
+ phase. image ?? Image ( nsImage: . init( ) )
110
+ #else
108
111
phase. image ?? Image ( uiImage: . init( ) )
112
+ #endif
109
113
}
110
114
}
111
115
@@ -201,10 +205,17 @@ public struct CachedAsyncImage<Content>: View where Content: View {
201
205
guard let url = url else { return }
202
206
let request = URLRequest ( url: url)
203
207
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
204
214
if let uiImage = UIImage ( data: data) {
205
215
let image = Image ( uiImage: uiImage)
206
216
phase = . success( image)
207
217
}
218
+ #endif
208
219
} catch {
209
220
phase = . failure( error)
210
221
}
You can’t perform that action at this time.
0 commit comments