path / FastImageCache

iOS library for quickly displaying images while scrolling
MIT License
8.1k stars 938 forks source link

Reporting network error from delegate's wantsSourceImageForEntity up to the app's code #26

Open oleksandr opened 10 years ago

oleksandr commented 10 years ago

I've noticed in the following call chain:

[FICImageCache asynchronouslyRetrieveImageForEntity:withFormatName:completionBlock:] -> [delegate wantsSourceImageForEntity:withFormatName:completionBlock:] -> AFHTTPRequest operation -> completionBlock(image)

There's no way to report a network layer error up to an app level caller. Passing nil to completionBlock simply ignores the lookup of the block in the dictionary inside of the FastImageCache.

Is there any way to overcome this design constraint?

mallorypaine commented 10 years ago

What would you want to do if the image couldn't be retrieved?

ghost commented 10 years ago

This is probably a design flaw. Where the source image comes from isn't important, but the caller to FIC to retrieve an image should be notified if anything goes wrong.

I believe a recent pull request fixes the case where passing a nil image to the delegate completion block does call the retrieval request completion block. So while there currently isn't any context to identify why the retrieval request wrong, you at least aren't left hanging anymore. Perhaps allowing the completion block to take a generic context pointer would let the source image provider pass back specific failure information to the caller.

oleksandr commented 10 years ago

Right, I don't care about the source but I need to handle the error case. Would be nice to extend the completion block with an extra error parameter which seems to be a common practice.

Goos commented 10 years ago

Hey there, I encountered the same issue, and saw that this commit had already solved my problem. Are you planning another cocoapods-version anytime soon? If so, that would be totes awesome.

Great job by the way, it's blazing fast!

sundarsan commented 10 years ago

Hey all ,

Is this enhancement done from library already? I need to handle the Network error scenario while fetching images , let me know how i can handle that plsss.

Thanks, Sundar

Goos commented 10 years ago

@sundarsan it was resolved here, but afaik the podspec isn't updated to the 1.3 tag. But if you use the latest version from github, it should work.