I want the user to have the ability to access all of their photos, but loading them all at once takes too long using PHAsset.fetchAssetsInAssetCollection
, especially if they have 500+ photos (I am displaying them in a collection view in a custom-built view). I was thinking about using scrollViewDidScroll
when the user reaches the end of the collection view to load the next set, but I do not know how to get the next x
amount from the photo library.
I limited the amount of photos they can get using fetchOptions.fetchLimit = x
, but I don't know how to tell the function where to begin fetching the assets. Is it possible?
Here is a snippet of my current code (the assetCollections
is set in a different part of the code):
let fetchOptions = PHFetchOptions()
fetchOptions.predicate = NSPredicate(format: kFormatOfPredicate, PHAssetMediaType.Image.rawValue)
fetchOptions.sortDescriptors = [NSSortDescriptor(key: kSortByCreationDateString, ascending: false)]
fetchOptions.fetchLimit = 32
//Only want camera roll
if assetCollection.localizedTitle == kCameraRollString {
assets = PHAsset.fetchAssetsInAssetCollection(assetCollection, options: fetchOptions)
if assets.count > 32 {
for i in 0..<32 {
if let asset = assets[i] as? PHAsset {
appendImageArray(assetToBeChanged: asset)
}
}
} else {
for i in 0..<assets.count {
if let asset = assets[i] as? PHAsset {
appendImageArray(assetToBeChanged: asset)
}
}
}
is there something I can add to my fetchOptions
to say which assets to start getting? Is there a better way entirely to do this? Let me know if you need me to post more code, and thank you in advance!