https://developer.apple.com/documentation/photokit
Work with image and video assets managed by the Photos app, including those from iCloud Photos and Live Photos.
Photos(사진) 앱에서 다루는 이미지 및 비디오 에셋을 사용해 작업합니다. 아이클라우드 사진 및 라이브 사진을 포함합니다.
iOS 및 macOS에서 PhotoKit
은 사진 앱을 위한 사진 편집 확장(extension)을 지원하는 클래스들을 제공합니다. iOS, macOS, tvOS에서 PhotoKit
은 사진 앱이 다루는 사진 및 비디오 에셋에 대한 직접적인 접근을 제공하기도 합니다.
PhotoKit
을 사용하면 디스플레이, 재생, 이미지 및 비디오 컨텐트 편집을 위한 에셋 가져오기와 캐시를 할 수 있으며, 앨범, 모멘트, 공유된 앨범과 같은 에셋 컬렉션을 관리할 수도 있습니다.
A representation of an image, video, or Live Photo in the Photos library.
Photos 라이브러리에 있는 이미지, 비디오, 라이브 포토의 표현입니다.
로컬 기기의 에셋을 불러올 수 있는 메소드가 여러 가지 있다. 한 가지만 살펴보면 아래와 같다.
class func fetchAssets(with: PHFetchOptions?) -> PHFetchResult<PHAsset>
아래처럼 사용할 수 있다.
var fetchedAssets: PHFetchResult<PHAsset>?
init() {
self.fetchedAssets = nil
}
func fetchAssets() {
fetchedAssets = PHAsset.fetchAssets(with: nil)
}
https://velog.io/@horus222128/PHAsset
An object that facilitates retrieving or generating preview thumbnails and asset data.
프리뷰 썸네일과 에셋 데이터를 검색 혹은 생성하는 것을 용이하게 해주는 객체입니다.
위에 있는 PHAsset
의 내용에서 메소드를 실행하면 에셋 전체를 가져온다. 에셋 유형에 따라 특정 에셋을 가져오는 메소드가 다르다. 이미지를 가져오는 경우 아래 메소드를 실행한다.
func requestFirstImage() {
guard let fetchedAssets = self.fetchedAssets else { return }
guard let firstAsset = fetchedAssets.firstObject else { return }
PHImageManager.default().requestImage(for: firstAsset, targetSize: CGSize(width: 100, height: 100), contentMode: .aspectFit, options: nil) { image, keyValue in
if let image = image {
print(image)
}
}
}
https://velog.io/@horus222128/PHImageManager
An object that manages access and changes to the user’s photo library.
사용자의 사진 라이브러리에 접근 및 변경을 관리할 수 있도록 해주는 객체입니다.