my collection view don't show gifs.. im using GIPHY.. and SwiftGif Extension, to show the gifs on UIImageView... this is the code
func searchGif(search: String) {
GiphyCore.configure(apiKey: "hRuR15WOxvhonLAsLhd0R8pDGvJxQYOk")
respondView.isHidden = true
_ = GiphyCore.shared.search(search, media: .gif, offset: 2, limit: 6, rating: .ratedG, lang: .english, completionHandler: { [weak self] (response, error) in
self?.isDataLoading = false
if let error = error {
print("error in response", error)
}
guard
let data = response?.data else { return }
self?.initialize()
for results in data {
let urlString = results.url
guard let url = URL(string: urlString) else { return }
do {
let data = try Data(contentsOf: url)
let foundedGif = GifModel(gifUrl: data, urlString: urlString)
self?.gifModel.append(foundedGif)
} catch let error as NSError {
print(error)
}
}
if self?.gifModel.isEmpty ?? false {
self?.setupNofound()
}
DispatchQueue.main.async {
self?.gifCollectionView.reloadData()
}
})
}
in the delegates on collection view...
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: GifSearchCollectionViewCell.identifier,
for: indexPath
) as? GifSearchCollectionViewCell else {
return UICollectionViewCell()
}
cell.gifModel = gifModel[indexPath.row]
return cell
}
and in the numberOfItems in sections
as well .....
I put gifModel.count
the data works good, I have a response with the 6 on the array model...
and in the cell:
@IBOutlet weak var splashGifView: UIImageView!
var gifModel: GifModel? {
didSet {
guard
let gif = gifModel?.gifUrl else { return }
splashGifView.image = UIImage.gifImageWithData(gif)
}
}
I tried with String but nothing, the cells already create, but don't show the gifs... someone can help?
update...
@IBOutlet weak var splashGifView: UIImageView!
var gifModel: GifModel? {
didSet {
guard let gif = gifModel? { return }
let url = gif.gifUrl. // <- this give nill
splashGifView.image = UIImage.gifImageWithData(url)
}
}
the url have nill, but in my model I have the data url correctly...