I need to get and show last taken 3 photos from photo library on viewDidload event without any clicks.
After this step I should get other photos 3 by 3 when I scroll the scrollview.
Do you know the proper way to do this with swift? Thanks.
I need to get and show last taken 3 photos from photo library on viewDidload event without any clicks.
After this step I should get other photos 3 by 3 when I scroll the scrollview.
Do you know the proper way to do this with swift? Thanks.
Here is @Lindsey Scott's answer but in Objective-C. I am putting the last 9 photos from Camera Roll into a collection view:
Here's a solution using the
Photos
framework available for devices iOS 8+ :Details
xCode 8.3, Swift 3.1
Code
Usage
Full Sample (collectionView with images from PhotoLibrary)
Add to Info.plist
Described above
Result
You can extract the 3 latest photos using functions in the
AssetsLibrary
framework. First you have to add the framework to the project. The following function retrieves the 3 latest photos and calls the completion block.The above function can be called like this
Here's an elegant solution with efficiency in Swift 4.
In short, we request the latest photo assets once, then convert them into image when needed.
First import Photos Library:
Then create a function to fetch the lastest photos taken:
In your case you might want to fetch enough photos at once (for example 50), then store the result somewhere in your view controller:
In
viewDidLoad
:Finally request the image at the right place (for example, a collection view cell):
Remember to add a property to your cell: