PhotosPickerItem
PhotosPickerItem
PhotosPickerItem Structure of PhotosUI A type that represents an item you use with a Photos picker.
struct PhotosPickerItemOverview
The selection results you get from PhotosPicker are placeholder objects. A PhotosPickerItem conforms to //com.apple.documentation/documentation/CoreTransferable/Transferable, and allows you to load the representation you request. To load a SwiftUI //com.apple.documentation/documentation/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.
Important: //com.apple.documentation/documentation/SwiftUI/Image only supports
PNGfile types through its //com.apple.documentation/documentation/CoreTransferable/Transferable conformance. For more information on creating a customTransferablemodel to support other image types, see //com.apple.photokit/documentation/PhotoKit/bringing photos picker to your swiftui app.