var posts = [Post]()
....
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath) as! FeedCollectionViewCell
cell.postTextView.text = posts[indexPath.item].caption
cell.postImageView.image = UIImage(named: "photoplaceholder.jpg")
let urlString = posts[indexPath.item].photoUrl
let url = URL(string: urlString)
let task = URLSession.shared.dataTask(with: url!){ data, reponse, error in
if error != nil {
print(error!)
} else{
DispatchQueue.main.async(execute: {
cell.postImageView.image = UIImage(data: data!)
})
}
}
task.resume()
return cell
}
}
Я хотел бы отобразить последнее сообщение вместо самого старого сообщения.
В то время как для tableview, posts [indexPath.row] .caption дает мне последнее сообщение,
для UICollectionView это не так, это дает мне самый старый пост. Мне нужна помощь, чтобы сначала отобразить последнее сообщение перед остальными.