2023-02-26 16:22:08 +01:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
2023-03-28 10:35:38 +02:00
|
|
|
// Licensed under the Apache License 2.0.
|
2023-02-26 16:22:08 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
public struct ImageFileTranseferable: Transferable {
|
|
|
|
let url: URL
|
|
|
|
lazy var data: Data? = try? Data(contentsOf: url)
|
2023-04-01 12:10:59 +02:00
|
|
|
|
2023-02-26 16:22:08 +01:00
|
|
|
public static var transferRepresentation: some TransferRepresentation {
|
|
|
|
FileRepresentation(contentType: .image) { image in
|
|
|
|
SentTransferredFile(image.url)
|
|
|
|
} importing: { received in
|
|
|
|
Self(url: localURLFor(received: received))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func localURLFor(received: ReceivedTransferredFile) -> URL {
|
|
|
|
let copy = URL.temporaryDirectory.appending(path: "\(UUID().uuidString).\(received.file.pathExtension)")
|
|
|
|
try? FileManager.default.copyItem(at: received.file, to: copy)
|
|
|
|
return copy
|
|
|
|
}
|