I need to fetch three photos sorted by the date taken - latest being the most recently taken. The way I am currently doing this is by fetching all photo assets then fetching the asset at the appropriate indexes (0, 1, 2). While this works, I am curious if there is a more efficient way to do this when I'm only interested in the top three. The docs explain the fetch doesn't return all image data - only metadata, but I still don't need to obtain all of the metadata. Is there a PHFetchOption
I could use to limit the fetch, or an NSPredicate
, or is that not necessary to worry about?
var assetsFetchResults = PHAsset.fetchAssetsWithMediaType(.Image, options: nil)
let imageManager = PHCachingImageManager()
if assetsFetchResults?.count > 0 {
var asset = assetsFetchResults?[0] as? PHAsset
imageManager.requestImageForAsset(asset, targetSize: targetSize, contentMode: .AspectFill, options: nil, resultHandler: ...)
}
//repeat for index 1 and 2