Fix by Dimillian

This commit is contained in:
Lumaa 2024-01-06 15:27:55 +01:00
parent 0095ae31a2
commit 81ef4bfc63
1 changed files with 6 additions and 6 deletions

View File

@ -3,22 +3,22 @@
import Foundation import Foundation
import SwiftUI import SwiftUI
// Doesn't seem to work? // Dimillian fixed it - https://mastodon.social/@dimillian/111708477095374920
struct AsyncImageTransferable: Codable, Transferable {
struct ShareableOnlineImage: Codable, Transferable {
let url: URL let url: URL
func fetchAsImage() async -> Image { func fetchAsImage() -> Image {
let data = try? await URLSession.shared.data(from: url).0 let data = try? Data(contentsOf: url)
guard let data, let uiimage = UIImage(data: data) else { guard let data, let uiimage = UIImage(data: data) else {
return Image(systemName: "photo") return Image(systemName: "photo")
} }
return Image(uiImage: uiimage) return Image(uiImage: uiimage)
} }
// MARK: A synchronous exporter should be used
static var transferRepresentation: some TransferRepresentation { static var transferRepresentation: some TransferRepresentation {
ProxyRepresentation { media in ProxyRepresentation { media in
await media.fetchAsImage() media.fetchAsImage()
} }
} }
} }