1
0
mirror of https://github.com/metabolist/metatext synced 2024-12-26 17:52:26 +01:00

Conditional import

This commit is contained in:
Justin Mazzocchi 2021-03-31 23:58:32 -07:00
parent da26a0f607
commit d0eba1e71a
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C

View File

@ -3,7 +3,9 @@
import Combine
import Foundation
import ImageIO
#if canImport(UIKit)
import UIKit
#endif
import UniformTypeIdentifiers
enum MediaProcessingError: Error {
@ -84,7 +86,8 @@ private extension MediaProcessingService {
}
static func UIImagePNGDataPublisher(itemProvider: NSItemProvider) -> AnyPublisher<Data, Error> {
Future<Data, Error> { promise in
#if canImport(UIKit)
return Future<Data, Error> { promise in
itemProvider.loadItem(forTypeIdentifier: UTType.image.identifier, options: nil) { item, error in
if let error = error {
promise(.failure(error))
@ -103,6 +106,9 @@ private extension MediaProcessingService {
}
}
.eraseToAnyPublisher()
#else
return Fail<Data, Error>(error: MediaProcessingError.invalidMimeType).eraseToAnyPublisher()
#endif
}
static func imageData(url: URL, type: UTType) throws -> Data {