Accessing Image(x) from the Camera Roll and or Photo Library

I am new to Swift and SwiftUI with an eagerness to learn.

What I thought to be a very simple task seems to either be difficult or impossible?

My app has 2 options. Randomly pick an image from the camera roll or get image(x). This needs to be done without user intervention. I understand there are privacy restrictions but I believe you can set the user to allow access?

I found something on stackoverflow.com. It mentions getting the last 3 images from the photo library. From what I understand and was reading there isn’t enough memory to load the entire library? Swift - how to get last taken 3 photos from photo library?

I feel like there has to be a way to ask Swift (prefer SwiftUI) to showmeimage(x).

Any help is beyond appreciated. I have been at this for 2 weeks and though I am a beginner I feel confident I can make this happen.

Hi Craig,

Welcome to the Code Crew community.

What have you implemented in code so far in order to get this project working?

1 Like

Hi @Chris_Parker,

Thank you very much for your quick reply. At this point it is more of “can it be done” I have been unable to find any code or samples with the exception of the stackoverflow question I came across.

In my C# experience I would do something like this.

var cameraImages = GetImagesFromCameraRoll()

// Now I have an array of camera images

cameraImages.Count() // this gives me a count of all images on the camera roll

Image(cameraImages(10)) // would show me the 10th picture in my camera roll.

That is what I am hoping to accomplish.

One thing you will have to come to grips with, if you are going to use SwiftUI and incorporate an ImagePickerController, is that you have to implement UIViewControllerRepresentable as there is no native functionality in SwiftUI to enable you to access the users camera roll in the same way as you would in UIKit. If you aren’t familiar with that then you need to have a look at the 100 Days of SwiftUI course that Paul Hudson has created. Project 13 covers that aspect beginning at Day 62 of the course.

1 Like