There are many caching libraries available in iOS. The most popular library is SDWebImage for caching images. There is one image cache library is HanekeSwift’s for image cache.
My question is What is main difference between SDWebImage and HanekeSwift’s if both are working same? In Which case we use SDWebImage or HanekeSwift’s?
There are few difference between SDWebImage and Haneke. So it depends on user's choice with which Caching Library they want to go.
Here are few:-
SDWebImage:-
1) Categories for UIImageView, UIButton, MKAnnotationView adding web image and cache management
2) A guarantee that the same URL won't be downloaded several times
3) An asynchronous memory + disk image caching with automatic cache expiration handling
Haneke:-
1) Generic cache with out-of-the-box support for UIImage, NSData, JSON and String
2) Zero-config UIImageView and UIButton extensions to use the cache, optimized for UITableView and UICollectionView cell reuse
SDWebImageCache:
Haneke:
Find various feature listing in below image to identify difference between all of them:-
Hope it helps you to distinguish all of them
Related
I'm wondering if you can help me solve more of a general, process question.
In my app when the user signs up, I create a thumbnail avatar (approx 35x35 px). I upload this to the server.
In another section of my app I display all users in a UITableView. This table is populated by a request that occurs on the view controller beforehand (so I can reduce loading screens).
This table contains approximately 100 rows. My question is, how do I load all the avatars seamlessly?
I dont want the user to tap the view and see a bunch of users, then avatars loading in randomly.
I dont want a loading screen to appear, unless its absolutely necessary (i.e. the user navigates through the app quickly).
I dont want to fire off 100 requests at once to my server.
I would like to send one request, and possibly get them back all at once. And if I did this, is there a specific format I should use? A big JSON response with base64 encoded thumbnails? :/
In addition to this, should I cache these? If so, how?
Swift 3.
Thanks!
SDWebImage is a really amazing framework that you can use to achieve this task. I've used it in every app of mine.
You can find it here: https://github.com/rs/SDWebImage
You can just put the following code in your cellForRowAtIndexPath Method
cell.imageView.sd_setImageWithURL(String.initWithURL("http://www.domain.com/path/to/image.jpg"))
The URL specified here is the link to the individual image to be shown in that particular row. This way your app can load images as the user scrolls the tableview. Given that your images are 35x35, it should be smooth and quick.
Hope this helped!
After more research based on Pratham Mehta's answer, I found a library called KingFisher:
https://github.com/onevcat/Kingfisher
This is more appropriate for my project, given SDWebImage is written in Objective-C, and my project is in Swift 3.
Check out Nuke. It's designed to support large collections of images (has built-in throttling, rate limiting of requests, etc).
And if I did this, is there a specific format I should use? A big JSON response with base64 encoded thumbnails? :/
I would suggest to avoid any premature optimizations - just download the images lazily one by one as soon as they appear on the display. Most image loading frameworks are designed to support this really well.
In addition you can prefetch the images.
If you want to do it the hard way - just zip the images and download the archive.
In addition to this, should I cache these? If so, how?
You may find this helpful.
Is it possible to do very basic image recognition to compare an image against a database of images(resource folder images or any web servers images if we have) and determine which image in the database is the best match? I don't need to do any processing of any of the images, but simply differentiate between a finite list of images.
Is it any open source code available ?
I would recommend using OpenCV if you simply want to compare images (i.e. decide if two images are the same).
Here is a similar question on SO:
iOS image comparison
I would also go about reading a little bit about what Core Image (the iOS image library) has to offer, before going about OpenCV or other 3rd party.
I hope this helps.
My model comes from Core Data.
My beans have images stored in the model as NSData.
To display my images, I need to do :
[UIImage imageWithData:bean.imageData]
Is it OK if I do that everywhere ? I mean, from view #1 I display image by creating [UIImage imageWithData:], then I go on view #2 where I need to display the same image, but I only pass the bean between the 2 views, so I recreate the UIImage with [UIImage imageWithData].
I am wondering whether it takes too many CPU or memory if I do this... Do I need to manage a cache myself ? I think this might be quite common use case with CoreData so is there a common pattern to handle this ?
imageWithData will not cache your image (as per the docs, the only UIImage method to cache is imageNamed)
Here is an algorithm for caching images, though.
In answer to your question, imageWithData is a bit slow, so, no you probably don't want to do this all over the place. You'd probably want to do some caching for maximum performance (or at least if you're likely to retrieve the same image repeated during a give session with the app). NSCache, like HalR suggested, is a great solution for that.
Furthermore, if the images are huge, you might not want to store them in CoreData at all, but rather store them in your Documents folder, and only store the filename path in CoreData. It's surprising how much slower it is to retrieve the image from your database and then use imageWithData is than it is to use imageWithContentsOfFile. Admittedly, if you're doing cacheing, you'll suffer this performance hit less often, but still, if you're retrieving lots of separate images, the difference is observable. With thumbnail images, though, it's less of an issue. Everyone draws this line in a different place, but for me, if the images are greater than 100kb each (or if I'm doing a lot of image retrieval), I'll use the Documents approach.
I'm looking to swap out the AFImageCache used by default in the UIImageView+AFNetworking category for something that's disk based and that can managed a little more accurately (something like NSURLCache). Unfortunately, since UIImageView+AFNetworking is a category and not a subclass, I can't just override af_sharedImageCache with a sublclass of UIImageView OR another category.
Is there any other way to achieve this functionality without copying and pasting most of UIImageView+AFNetworking into my own subclass?
The SDWebImage project provides a similar UIImageView category, but offers both in-memory (using NSCache) and on-disk (using NSFileManager) caching. I'd recommend just using that when you need to cache to disk.
The downside to this implementation is that your network requests won't go through your AFHTTPClient subclass, so depending on what your needs are you might need to implement your own operation queue, authentication, etc. If you're just using it for something basic, like displaying avatar images in a table view, it should be fine.
If that downside bothers you, an alternate idea would be to use SDImageCache (included in the SDWebImage project) to cache the images, and download them yourself using AFNetworking.
Finally, note that AFNetworking has built-in support for NSURLCache, and if you create one it will cache your images to disk. However, image caching is typically used for showing lots of images in a UIScrollView, and NSURLCache doesn't have good enough performance for smooth scrolling.
I have a fork of AFNetworking that includes file cache in the NSCachesDirectory.
You can find it here: https://github.com/andyast/AFNetworking_FileCache
There is a branch that is compatible with V1.3.3 if you need that as well.
While I have been working with iOS apps for some time now, I am totally new to core data. So, just have a simple question.
Can images be cached and stored in core data?
I could not find any sample app for caching images into core data. It would be of great help if someone can share me links for image caching in core data in case this is possible.
[P.S I know image caching. So, not looking for links or samples for only image caching. Please share info on image caching with core data]
You can take a look at this article.
But IMO it's better to just store imageURLs in your Core Data database and cache them with setImageWithURL:placeholderImage: (AFNetworking awesomeness).
Check one of the below tutorials:
Core Data Image Caching
File System vs Core Data: the image cache test
USING COREDATA TO CACHE AND DISPLAY IMAGES VIA INSTAGRAM