forked from arthurhammer/FrameGrabber
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhotoAlbums.swift
More file actions
42 lines (34 loc) · 1.23 KB
/
PhotoAlbums.swift
File metadata and controls
42 lines (34 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import PhotoAlbums
import Photos
// App-specific albums configuration.
extension AlbumsDataSource {
static let smartAlbumTypes: [PHAssetCollectionSubtype] = [
.smartAlbumUserLibrary,
.smartAlbumFavorites,
.smartAlbumSlomoVideos,
.smartAlbumTimelapses
]
static func makeDefaultDataSource() -> AlbumsDataSource {
let assetOptions = PHFetchOptions.assets(filteredBy: .videoAndLivePhoto)
return AlbumsDataSource(
smartAlbumsOptions: .init(types: smartAlbumTypes, assetOptions: assetOptions),
userAlbumsOptions: .init(assetOptions: assetOptions)
)
}
/// The "Recents" smart album to display initially.
static func fetchFirstAlbum() -> PHAssetCollection? {
guard let type = smartAlbumTypes.first else { return nil }
return PHAssetCollection.fetchAssetCollections(
with: .smartAlbum,
subtype: type,
options: nil
).firstObject
}
}
extension PHFetchOptions {
static func assets(filteredBy filter: PhotoLibraryFilter) -> PHFetchOptions {
let options = PHFetchOptions()
options.predicate = filter.photoLibraryFetchPredicate
return options
}
}