Skip to content

Instantly share code, notes, and snippets.

@tbatsuur
Created October 16, 2018 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbatsuur/f666ba6da81cfe71801a0f6f12cea86c to your computer and use it in GitHub Desktop.
Save tbatsuur/f666ba6da81cfe71801a0f6f12cea86c to your computer and use it in GitHub Desktop.
private func loadImage() -> UIImage? {
let manager = PHImageManager.default()
let fetchResult: PHFetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions())
// 1
var image: UIImage? = nil
// 2
manager.requestImage(for: fetchResult.object(at: 0), targetSize: CGSize(width: 647, height: 375), contentMode: .aspectFill, options: requestOptions()) { img, err in
// 3
guard let img = img else { return }
image = img
}
return image
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment