let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
let fetchResult = PHAsset.fetchAssets(with: fetchOptions)
return fetchResult.firstObject
1. PHFetchOptions 선언하기
➡️ 에셋 또는 컬렉션 객체를 가져올 때 Photos에서 반환하는 결과에 필터링, 정렬 등 영향을 주는 옵션
2. PHFetchOptions 내 sortDiscriptors 의 key를 "creationDate" 로 지정
3. fetch할 때 해당 PHFetchOption을 등록해 옵션을 건 채로 에셋을 받아오면 된다.
sortDescriptors - PHFetchOptions | Apple Developer Documentation
Instance Property sortDescriptors A list of sort descriptors, specifying an order for the fetched objects. DeclarationDiscussionConstruct sort descriptors with the properties of the objects that you want to fetch, listed in Table 1. For example, the follow
developer.apple.com
'iOS' 카테고리의 다른 글
[iOS] Photos - Requesting changes to the Photo Library (0) | 2020.06.08 |
---|---|
[iOS] Photos - Asset Loading (0) | 2020.06.08 |
[iOS] Photos Framework (0) | 2020.06.08 |
[iOS] DispatchQueue로 비동기 프로그래밍 (0) | 2020.06.08 |
[iOS] 서버에 데이터 요청하기 : URLSessionDataTask (0) | 2020.06.08 |