Latest 2.2.3
Homepage https://github.com/1amageek/PHFetchedResultsController
License MIT
Platforms ios 8.0
Authors

A fetchedResultsController for PhotoKit. It can be divided into sections by date PhotoKit

Usage


- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return self.fetchedResultsController.sections.count;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    id <PHFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section];
    return [sectionInfo numberOfObjects];
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    Header *header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"Header" forIndexPath:indexPath];
    id <PHFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:indexPath.section];
    header.title = [sectionInfo name];
    return header;
}

- (PHFetchedResultsController *)fetchedResultsController
{
    if (_fetchedResultsController) {
        return _fetchedResultsController;
    }
    PHFetchResult *assetCollections = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum
                                                                               subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary
                                                                               options:nil];
    PHAssetCollection *assetCollection = assetCollections.firstObject;

    _fetchedResultsController = [[PHFetchedResultsController alloc] initWithAssetCollection:assetCollection sectionKey:PHFetchedResultsSectionKeyWeek mediaType:PHFetchedResultsMediaTypeImage ignoreLocalIDs:@[]];
    _fetchedResultsController.delegate = self;
    _fetchedResultsController.dateFormateForSectionTitle = @"yyyy.MM.DD";

    [_fetchedResultsController performFetch:nil];

    return _fetchedResultsController;
}

Latest podspec

{
    "name": "PHFetchedResultsController",
    "version": "2.2.3",
    "summary": "A fetchedResultsController for PhotoKit. It can be divided into sections by date PhotoKit",
    "homepage": "https://github.com/1amageek/PHFetchedResultsController",
    "license": {
        "type": "MIT"
    },
    "authors": {
        "1_am_a_geek": "[email protected]"
    },
    "social_media_url": "http://twitter.com/1amageek",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/1amageek/PHFetchedResultsController.git",
        "tag": "2.2.3"
    },
    "source_files": [
        "PHFetchedResultsController/PHFetchedResultsController.{h,m}"
    ]
}

Pin It on Pinterest

Share This