Using the New PHPicker With SwiftUI
1. Add PHPicker to SwiftUI

So, let’s introduce PHPicker to this app.

In order to use PHPicker in SwiftUI, we need to prepare the view that conforms to the UIViewRepresentable protocol and create an instance of PHPicker inside of it.

Ths step of connecting to PHPicker goes as follows:

Create a view that conforms to UIViewRepresentable .

. Add the makeUIViewController method and provide a PHPicker view.

method and provide a view. Add updateUIView .

. Add a Coordinator class and makeCoodinator method.

So, create ImagePicker.swift at the root folder:

makeUIViewController is in charge of creating an instance of PHPicker and returning it. The configuration should be done here.

makeCoodinator provides a coordinator class that handles all of the events of PHPicker .

The Coordinator class is used to handle the picker event and triggers the completion handler after getting data from the Photo Library.

In this case, we’re supposed to handle multiple photos.

Next, we will use this view in ContentView.swift :

ContentView.swift

In pickerConfiguration , you can customize the configuration to whatever you want. In this case, we only use .image data and set a limit of 10 pics.

When the “Add photos” button pressed, the Photo Library shows up and you can select multiple photos:

GIF

It seems to work fine.
['Bere Tan']
['Swiftui', 'Simple', 'Small Business', 'Software Development', 'PHP']