There doesn't seem to be a good way to do this yet for SwiftUI previews. It does seem to be related to privacy approval. There is a bit of a hack that seems to work.
You'll need a program to edit SQLite databases. I use the free DB Browser for SQLite
.
Step 1. Run your app in the iOS simulator and accept all photo library permissions.
Step 2. In your SQL editor, open the simulator's privacy database:
~/Library/Developer/CoreSimulator/Devices/<SIMULATOR>/data/Library/TCC/TCC.db
Step 3. Copy the necessary kTCCServicePhotos
row from the access
table
Step 4. Insert the row into the SwiftUI previews' privacy database:
~/Library/Developer/Xcode/UserData/Previews/Simulator Devices/<SIMULATOR>/data/Library/TCC/TCC.db
You now have your SwiftUI Previews' photo privacy approved. You should see the default simulator photos appear in the preview now.
If you want to add your own photos into the mix, you can drag them onto the iOS Simulator. Then copy the contents of the .../<SIMULATOR>/data/Media/DCIM/100Apple
and .../<SIMULATOR>/data/Media/PhotoData
folders across to the corresponding SwiftUI preview simulator.
I'm developing a photo app with a custom SwiftUI photo library manager. It's a real pain not being able to see photos in the preview. I found your question and my heart sank when I saw it was unanswered. So I spent the afternoon nutting it out