PhotosPickerItem
A type that represents an item you use with a Photos picker.
Declaration
struct PhotosPickerItemOverview
The selection results you get from PhotosPicker are placeholder objects. A PhotosPickerItem conforms to Transferable, and allows you to load the representation you request. To load a SwiftUI Image and track progress, use loadTransferable(type:completionHandler:).
func loadTransferable(from imageSelection: PhotosPickerItem) -> Progress {
return imageSelection.loadTransferable(type: Image.self) { result in
DispatchQueue.main.async {
guard imageSelection == self.imageSelection else { return }
switch result {
case .success(let image?):
// Handle the success case with the image.
case .success(nil):
// Handle the success case with an empty value.
case .failure(let error):
// Handle the failure case with the provided error.
}
}
}
}A failure can occur when the system attempts to retrieve the data. For example, if the picker tries to download data from iCloud Photos without a network connection.