Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer accessing fetchResults settings #315

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

natecraft1
Copy link

Issue

Setting custom fetchResults prior to obtaining Photos permission from the user results in null AssetCollections, and thus will present an empty ImagePickerController the first time it is presented.

For instance

let imagePickerVC = ImagePickerController()
imagePickerVC.settings.fetch.album.fetchResults = [PHAssetCollection.fetchAssetCollection(with: .album, subtype: .albumRegular, options: PHFetchOptions())]
imagePickerVC.presentImagePicker(...

will have the effect of presenting an empty picker the first time after permissions are first granted.

Proposed solution
Defer the access of the fetchResults settings by using a function rather than a var.

Note
There are other ways of solving this, such as adding an onAuthorization closure to the presentImagePicker call and allowing settings to be passed in there.

public lazy var fetchResults: [PHFetchResult<PHAssetCollection>] = [
PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumUserLibrary, options: options),
]
public lazy var fetchResults: () -> [PHFetchResult<PHAssetCollection>] = { [options] in

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public lazy var fetchResults: () -> [PHFetchResult<PHAssetCollection>] = { [options] in
public lazy var fetchResults: () -> [PHFetchResult<PHAssetCollection>] = {

PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumUserLibrary, options: options),
]
public lazy var fetchResults: () -> [PHFetchResult<PHAssetCollection>] = { [options] in
return [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return [
[

@mikaoj
Copy link
Owner

mikaoj commented Dec 19, 2021

Sure makes sense. Wouldn't some of the examples also need to be updated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants