31 lines
952 B
Swift
31 lines
952 B
Swift
//
|
|
// PhotosHelper.swift
|
|
// PhotoRank
|
|
//
|
|
// Created by Shadowfacts on 8/3/19.
|
|
// Copyright © 2019 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import Photos
|
|
|
|
struct PhotosHelper {
|
|
private static let imageManager = PHCachingImageManager()
|
|
|
|
private init() {}
|
|
|
|
static func requestFullSizeImage(for asset: PHAsset, completion: @escaping (UIImage) -> Void) {
|
|
imageManager.requestImageData(for: asset, options: nil) { (data, _, _, _) in
|
|
guard let data = data, let image = UIImage(data: data) else { fatalError() }
|
|
completion(image)
|
|
}
|
|
}
|
|
|
|
static func requestThumbnail(for asset: PHAsset, targetSize: CGSize, completion: @escaping (UIImage) -> Void) {
|
|
imageManager.requestImage(for: asset, targetSize: targetSize, contentMode: .aspectFill, options: nil) { (image, _) in
|
|
guard let image = image else { return }
|
|
completion(image)
|
|
}
|
|
}
|
|
}
|