Skip to content
New issue

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

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

Already on GitHub? # to your account

Automatically validate file URLs #19

Closed
wants to merge 2 commits into from

Conversation

alexanderedge
Copy link
Contributor

This PR is in response to #18

There is no response object when loading from file URLs, but the data is available to use. We should check that the request URL is a file URL and return true in the validation function.

@cnoon
Copy link
Member

cnoon commented Sep 23, 2015

Thanks for your PR @alexanderedge. As mentioned in #18, I don't think this is something that we should support in AlamofireImage at this time.

If you want to use local images, you can simply load the image from the URL or using UIImage(named:). Then if you need to apply it using a custom transition, you can replicate some of the logic image transition logic for your own purposes. You could also leverage some of the other features of AlamofireImage such as ImageFilters and the ImageCache if you needed them.

I'm going to think on this some more. It's certainly outside of what it was originally designed to do. If it was implemented, there would need to be different setImageWithFileURL types of methods to call through.

@alexanderedge
Copy link
Contributor Author

Hi @cnoon, thanks for letting me know. Allow me to give you a bit of background into why I made this change:

Say I have a user profile model with a profileImageURL property of type NSURL. If the images are remotely stored, I can use AlamofireImage to retrieve them. If I want to provide mock data for testing, I can use the same NSURL interface but with static files on disk or in the application bundle. I don't want to change my model or the application when changing between test data and real data, and given that NSURLSession supports reading from file URLs, it makes sense that AlamofireImage should, too.

@cnoon
Copy link
Member

cnoon commented Sep 26, 2015

Thank you for the explanation @alexanderedge! I didn't know you could use fileURLs with an NSURLSession. It's not really documented from what I can tell nor do mocking libraries out there ever use this approach. Learn something every day! 🍻

Armed with this new knowledge, I think this is a great change. I pushed a slightly modified version of your PR in e5a91f9.

@cnoon cnoon added this to the 1.1.2 milestone Sep 26, 2015
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants