Skip to content

Commit

Permalink
Handle Multithumb when photo library has less than 4 images
Browse files Browse the repository at this point in the history
We didn't take into account that case, this leaded to some crashes for
libraries with less than 4 images. We also changed the update second
level cell to always set multithumb images, even when less than 4 are
present
  • Loading branch information
Francesco Bigagnoli committed Sep 12, 2018
1 parent 8ebeca1 commit 6a51a5e
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ final class AssetCollectionsViewController: UIViewController {
// Load random images for 2nd level MultiThumbnail imageview
let fetchOptions = PHFetchOptions()
fetchOptions.fetchLimit = MultiThumbnail.numOfThumbs
let assets = PHAsset.fetchAssets(with: .image, options: fetchOptions).objects(at: IndexSet(0..<MultiThumbnail.numOfThumbs))
for asset in assets {
let assets = PHAsset.fetchAssets(with: .image, options: fetchOptions)
let multiThumbAssetsNum = min(MultiThumbnail.numOfThumbs, assets.count)
let multiThumbAssets = assets.objects(at: IndexSet(0..<multiThumbAssetsNum))
for asset in multiThumbAssets {
let imageRequestOptions = PHImageRequestOptions()
imageRequestOptions.isNetworkAccessAllowed = true
cachingImageManager.requestImage(for: asset,
Expand Down Expand Up @@ -314,9 +316,7 @@ extension AssetCollectionsViewController {
}

private func updateSecondLevelCellThumbnail(_ albumCell: AssetCollectionCell) {
if randomImages.count >= MultiThumbnail.numOfThumbs {
albumCell.setMultipleThumbnails(Array(randomImages.values))
}
albumCell.setMultipleThumbnails(Array(randomImages.values))
}
}

Expand Down

0 comments on commit 6a51a5e

Please sign in to comment.