UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"xx.jpg"]
UIImage *img = [UIImage imageNamed:@"xx.jpg"]
In the second type will the image get cached ?
Whereas the in the first type the images doesn't get cached?
UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"xx.jpg"]
UIImage *img = [UIImage imageNamed:@"xx.jpg"]
In the second type will the image get cached ?
Whereas the in the first type the images doesn't get cached?
Correct, the second item is cached.
@Dan Rosenstark answer in swift..
Just wanted to leave this here to help deal with the pathnames issue. This is a method that you can put on a
UIImage
category.If you don't have an easy way to switch to cached, you might end up just using `imageNamed. This is a big mistake in most cases. See this great answer for more details (and upvote both question and answer!).
The
-initWithContentsOfFile:
creates a new image without caching, it's an ordinary initialization method.The
+imageNamed:
method uses cache. Here's a documentation from UIImage Reference:UIImage will retain loaded image, keeping it alive until low memory condition will cause the cache to be purged.
Update for Swift: In Swift the
UIImage(named: "...")
function is the one that caches the image.