1
0
mirror of https://github.com/metabolist/metatext synced 2024-12-27 02:02:38 +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 Combine
import Foundation import Foundation
import ImageIO import ImageIO
#if canImport(UIKit)
import UIKit import UIKit
#endif
import UniformTypeIdentifiers import UniformTypeIdentifiers
enum MediaProcessingError: Error { enum MediaProcessingError: Error {
@ -84,7 +86,8 @@ private extension MediaProcessingService {
} }
static func UIImagePNGDataPublisher(itemProvider: NSItemProvider) -> AnyPublisher<Data, Error> { 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 itemProvider.loadItem(forTypeIdentifier: UTType.image.identifier, options: nil) { item, error in
if let error = error { if let error = error {
promise(.failure(error)) promise(.failure(error))
@ -103,6 +106,9 @@ private extension MediaProcessingService {
} }
} }
.eraseToAnyPublisher() .eraseToAnyPublisher()
#else
return Fail<Data, Error>(error: MediaProcessingError.invalidMimeType).eraseToAnyPublisher()
#endif
} }
static func imageData(url: URL, type: UTType) throws -> Data { static func imageData(url: URL, type: UTType) throws -> Data {