Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add image literal to an array and show them?

I was trying to add image literals to array and display them as per the index.

Here is my code :

var images = [#imageLiteral(resourceName: "male-circle-128"),#imageLiteral(resourceName: "add_to_favourite-128"),#imageLiteral(resourceName: "28468-200"),#imageLiteral(resourceName: "progress_circular"),#imageLiteral(resourceName: "logout-1-128")]

and showing like this

cell!.imageView?.image = UIImage.init(cgImage: images[indexPath.row] as! CGImage)

got EXC_BAD_INSTRUCTION! what is the proper way to do this

enter image description here

like image 489
Vinu David Jose Avatar asked Dec 18 '25 00:12

Vinu David Jose


2 Answers

let images:[UIImage] = [array of image literal goes here]

like image 166
Ajay Singh Mehra Avatar answered Dec 20 '25 15:12

Ajay Singh Mehra


You can simply create array of image literals like:

var images = [#imageLiteral(resourceName: "image1"),#imageLiteral(resourceName: "image2"]
like image 34
Abdul Karim Khan Avatar answered Dec 20 '25 14:12

Abdul Karim Khan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!