I have images in Assets.xcassets named city_00,city_01,...,city_10
I stored them in an array
let cityImages: [UIImage] = [UIImage(named: "city_00")!,UIImage(named: "city_01")!,.....UIImage(named: "city_10")!]
let cityNames = ["City A","City B",....., "City J"]
Then I call them using collectionview
in my project and allow users to select any city they like
var imageSelected = [UIImage]()
var cityImage:UIImage?
var cityImageName:String?
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
collectionView.allowsMultipleSelection = false
cityImage = imageSelected[(indexPath as NSIndexPath).row]
let selectedImgName = String(format: "%%" ,imageSelected[(indexPath as NSIndexPath).row])
cityImageName = selectedImgName
}
How do I store the name of city in cityImageName
based on image selected?