0

I'm trying to retrieve the last photo (last item) from the photos library. I'm using the following code to do that:

let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
fetchOptions.fetchLimit = 1

let fetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions)

The thing is that I have added an image to my photos library which has an old creation date from like 2012. So even though that image is at the end of the list in the photos app it's not being retrieved because the creationDate is old. I tried using fetchOptions.sortDescriptors = [NSSortDescriptor(key: "modificationDate", ascending: false)] to no avail.

Is there a way to fetch the last image from the photos library (independently of creationDate)?

Peter Warbo
  • 10,972
  • 14
  • 93
  • 189
  • Please see this link https://stackoverflow.com/questions/28259961/swift-how-to-get-last-taken-3-photos-from-photo-library – Rajeev Singh Jul 05 '17 at 12:01
  • @RajeevSingh did you read my question at all? I can't sort with creationDate because an image can have an old creationDate and still be the last photo in the photo library. – Peter Warbo Jul 05 '17 at 12:42

0 Answers0