Skip to content

Commit

Permalink
Adopt PHPickerResultImageDataProvider to strict concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Jun 11, 2024
1 parent ccb87f9 commit 17fee78
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Foundation

#if os(iOS) || os(macOS) || os(visionOS)

import PhotosUI
@preconcurrency import PhotosUI

/// A data provider to provide image data from a given `PHPickerResult`.
@available(iOS 14.0, macOS 13.0, *)
Expand All @@ -37,6 +37,8 @@ public struct PHPickerResultImageDataProvider: ImageDataProvider {
/// The possible error might be caused by the `PHPickerResultImageDataProvider`.
/// - invalidImage: The retrieved image is invalid.
public enum PHPickerResultImageDataProviderError: Error {
/// An error happens during picking up image through the item provider of `PHPickerResult`.
case pickerProviderError(Error)
/// The retrieved image is invalid.
case invalidImage
}
Expand Down Expand Up @@ -64,10 +66,10 @@ public struct PHPickerResultImageDataProvider: ImageDataProvider {
self.contentType = contentType
}

public func data(handler: @escaping (Result<Data, Error>) -> Void) {
public func data(handler: @escaping @Sendable (Result<Data, Error>) -> Void) {
pickerResult.itemProvider.loadDataRepresentation(forTypeIdentifier: contentType.identifier) { data, error in
if let error {
handler(.failure(error))
handler(.failure(PHPickerResultImageDataProviderError.pickerProviderError(error)))
return
}

Expand Down

0 comments on commit 17fee78

Please sign in to comment.