iosswiftios8photosframework

fetchAssetCollectionsWithType to only retrieve videos


I am working on making a custom Gallery view in iOS for that I am using the Photos Framework that so far works great one thing that I can't get it to work is fetch the result to only return VIDEOS

I tried that let result = PHAssetCollection.fetchAssetCollectionsWithType(.Moment, subtype: .SmartAlbumVideos, options: nil) but it's still retrieving images I wonder is the syntax if wrong

Thanks for the help


Solution

  • Ok I found the answer of my question Basically I needed to use a predicate this is basically saying retrieve assets where the mediatype is video and also sort it by creationDate

    let allVideosOptions = PHFetchOptions()
    allVideosOptions.predicate = NSPredicate(format: "mediaType == %d", PHAssetMediaType.Video.rawValue)
    allVideosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
    videos = PHAsset.fetchAssetsWithOptions(allVideosOptions)