How to show SwiftUI PhotosPicker programatically

Hi I would like to show the PhotosPicker programatically the same way we can do with sheet(isPresented: Binding<Bool>) and fullScreenCover(isPresented: Binding<Bool>), i.e. I would like:

photosPicker(isPresented: Binding<Bool>, selectedItem: Binding<PhotosPickerItem?>).

This would allow me to have multiple buttons that show the picker and would make all my code that shows sheets consistent, thanks for reading.

Answered by BabyJ in 726049022

There is already a modifier for this. It has the same parameters as the PhotosPicker view and comes in its different variants.

photosPicker(isPresented:selection:maxSelectionCount:selectionBehavior:matching:preferredItemEncoding:photoLibrary:) -> some View

I couldn't find it in the documentation, but you can find it in Xcode's generated interface for SwiftUI.

Accepted Answer

There is already a modifier for this. It has the same parameters as the PhotosPicker view and comes in its different variants.

photosPicker(isPresented:selection:maxSelectionCount:selectionBehavior:matching:preferredItemEncoding:photoLibrary:) -> some View

I couldn't find it in the documentation, but you can find it in Xcode's generated interface for SwiftUI.

Might be as apple engineer you have some future versions on your desktop :-) I'm using Xcode 14.2 currently, no "isPresented" option is shown when typing PhotosPicker ... Or was it removed again?

How to show SwiftUI PhotosPicker programatically
 
 
Q