У меня есть массив вроде [Any]
, я просто добавляю элемент String
И элемент UIImage
.
в конце я перечисляю его в UITableView
, где мне нужно показать изображение, где индекс массива имеет UIImage
, и строку, где индекс элемента имеет тип String
.
class PhotosVC: UIViewController {
var arrPhotos: [Any] = [Any]()
override func viewDidLoad() {
self.arrPhotos.append("stringValue")
self.arrPhotos.append(pickedImage)
self.collectionViewData.reloadData()
}
}
extension PhotosVC: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return arrPhotos.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PhotosDescCell", for: indexPath) as! PhotosDescCell
if arrPhotos[indexPath] == String { // how to check here is element is String type or UIImage
cell.lblDesc.text = arrPhotos[indexPath] as? String
}
else {
cell.imgPhotos.image = arrPhotos[indexPath.row] as? UIImage
}
return cell
}
}