In my app I want to show gifs from giphy. The fetching and everyting is no problem, but I don't know what's the best way to display for example all trending gifs. I have a collectionview which should display all gifs with this code:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: GifChooserCell.cellIdentifier, for: indexPath) as! GifChooserCell
let data = try! Data(contentsOf: gif.giphyURL)
let image = FLAnimatedImage(animatedGIFData: data)
cell.image.animatedImage = image
return cell
}
The problem is that this loads everything into RAM and the application is extremely slow. What's the best way to do this? Async? Lazy loading?