UICollectionView with data source fetched from Photos - slow updates with big amount of photos

66 views Asked by At

I am making the app for detecting screenshots in Photos library using old ALAseetLibrary framework — please use new Photos framework if you can. My problem is, when user has big photo library it takes a lot of time to find screenshots. I am updating my data source every time app is opened.

Here's the code for scanning the photo library:

ALAssetsLibraryGroupsEnumerationResultsBlock savedPhotosBlock = ^(ALAssetsGroup *group, BOOL *stop)
{
    if (group)
    {
        [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
        {
             if(result)
             {
                 ALAssetRepresentation *original = [result defaultRepresentation];
                 CGSize dimensions = [original dimensions];

After this work is finished I am calling reloadData(). How can I update the data on the go so it is possible to interact with UICollectionView while its data source is updating?

1

There are 1 answers

0
Ruchish Shah On

You should use performBatchUpdate method. create array with new indexPath to be added. call insertItemsAtIndexPaths:

instead of reloadData