I am new to swift, and I am building an App that download images from the Internet and display in a UICollectionView, I can achieve this function successfully, however, it seems
Use AlamofireImage
Swift 2.2 or 2.3
Add --> pod 'AlamofireImage', '~> 2.5' in your pod file.
Swift 3.1
Add --> pod 'AlamofireImage', '~> 3.3' in your pod file.
Put the following line in your code which will automatically cache the image and download it as well.
override func viewDidLoad() {
super.viewDidLoad()
//hit your web service here to get all url's
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return arrImageURL.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
cell.imgViewPhoto.af_setImageWithURL(arrImageURL[indexPath.row], placeholderImage: UIImage())
}
Kingfisher is a lightweight and pure Swift implemented library for downloading and caching image from the web. This project is heavily inspired by the popular SDWebImage. And it provides you a chance to use pure Swift alternative in your next app. kingfisher