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

Support for URL instead of NSURL #18

Closed
2 tasks done
aheze opened this issue Dec 31, 2020 · 5 comments · Fixed by #21
Closed
2 tasks done

Support for URL instead of NSURL #18

aheze opened this issue Dec 31, 2020 · 5 comments · Fixed by #21

Comments

@aheze
Copy link
Contributor

aheze commented Dec 31, 2020

New Feature Request Checklist

  • I have checked the current documentations or APIs and did not find a solution
  • I have searched for a similar issue in the project and found none

Feature Request Description

Currently, you make a NSURL from PHAsset like this:

// Create with `PHAsset`
let asset: PHAsset
let photosURL = NSURL.sd_URL(with: asset)

// Load image (assume using custom manager)
imageView.sd_setImage(with: photosURL, placeholderImage: nil, context: [.customManager: manager])

However, sd_setImage(with: takes a URL, not NSURL.

Screen Shot 2020-12-30 at 8 20 47 PM

I would like to be able to get a URL from PHAsset, something like this:

// Create with `PHAsset`
let asset: PHAsset
let photosURL = URL.sd_URL(with: asset) /// URL not NSURL

// Load image (assume using custom manager)
imageView.sd_setImage(with: photosURL, placeholderImage: nil, context: [.customManager: manager])

This would avoid the error, and I think URLs are safer than NSURLs.

@dreampiggy
Copy link
Collaborator

This is limit in current Pure Objective-C implementation...

That NSURL category return type can not been autoamtically converted into URL sturct and may loss information.

@dreampiggy
Copy link
Collaborator

dreampiggy commented Dec 31, 2020

Can the Fix-it with as URL? solve the issue ?

@aheze
Copy link
Contributor Author

aheze commented Dec 31, 2020

@dreampiggy yes, as URL? works.

let asset: PHAsset
let photosURL = NSURL.sd_URL(with: asset)
cell.imageView.sd_setImage(with: photosURL as URL?, placeholderImage: nil) /// this works

@dreampiggy
Copy link
Collaborator

I'll update readme now.

For better Swift support, let me find some other way, or provide something like SDWebImage/SDWebImage#2980

Provide this repo as an Objective-C/Swift Mixed project.

@dreampiggy
Copy link
Collaborator

@aheze Introduce the convenience API for Swift user. See #21

let asset: PHAsset
let url = asset.sd_URLRepresentation

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