Currently, I am fetching imageUrls from Firestore using my 'tuwos' delegate (code not included). I then use a forIn loop, where I use a print statement to make sure each individual imageUrl has been fetched successfully (they are). Also in my forIn loop, I use the Kingfisher cocoapod to set an imageView's image based on each imageUrl. Finally, I return imageView.image, but the default image, "girl_0", is being shown each time, meaning images are not being displayed from Firestore.
func pickerView(_ pickerView: AKPickerView, imageForItem item: Int) -> UIImage {
let tuwos = self.delegate?.tuwos
let imageView = UIImageView(image: #imageLiteral(resourceName: "jane2"))
if item == 0 {
for (index, element) in tuwos!.enumerated() {
if index == 0 {
let imageName = "\(element.profileImageUrl)"
print("element image url:", element.profileImageUrl)
let url = URL(string: imageName)
imageView.kf.setImage(with: url)
}
}
}
imageView.image = UIImage(named: "girl_0")!.imageWithSize(CGSize(width: 82, height: 82))
return imageView.image!
}
Other info: (1) I'm using the AKPickerView cocoapod for a Horizontal Picker View, but the logic seems the same ('item' refers to their index). (2) The 'tuwos' delegate is referring to where I query Firestore. (3) I only set the code to execute for 'if item == 0' to see if it would execute at all, then was planning to figure out an abstraction to execute for each item in my pickerView. I suspect my problem is to do with my forIn loop, and that nothing is executing outside of it, hence returning the default for item 0.
This is my first post so apologies if I've missed anything, but happy to provide any info you need. I have looked around quite a lot trying to get the answer on my own (URLSession/kingfisher/sdwebimage/escaping closure/forin loop articles) but struggling on this one.