Fetch last item of core data attribute

In my swift code below my goal is fetch the last image of the core data array. Right now my code is having a runtime error with indexpath. I dont know if you need to use a index path to do this. I have also added a screenshot that features all of the core data info.

e0Ay9

var pic = UIImageView()
    func loadImage(){
        if let imageData = itemNamez[IndexPath.last(pic)] {

            let coredataLoadedimage = UIImage(data: imageData)
            pic.image = coredataLoadedimage

        }
    }

@pietrorea suggestions?

Your screenshot does not provide all the needed Core Data info. All your screenshot shows is you have an Info entity with attributes name and pic.

You said

fetch the last image of the core data array

Where is your code to fetch the images? Where do you declare the core data array?

What is itemNamez?

What is the problem you are having? Is the if-let block not executing?

Without answers to these questions, no one can help you.

This topic was automatically closed after 166 days. New replies are no longer allowed.