Reputation: 513
I have some performance problem with NSData dataWithContentsOfURL...
NSURL *url = [NSURL URLWithString:Imagepath];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img=[UIImage imageWithData:data];
[ArrayImages addObject:img];
This code is placed in a method that manage a JSON response got from an NSUrl connection(after calling my web service). All the code in this method is already in a background thread, moving this piece of code out the background thread do not solve the issue.. All the retrieved image are placed in a view in main thread. What i can do to make dataWithContentsOfURL faster or there is a alternative to dataWithContentsOfURL?
Thanks In Advance
Upvotes: 2
Views: 2747
Reputation: 104698
+[NSData dataWithContentsOfURL:]
is not "slow". If loading one image takes a long time, the problem lies elsewhere.
Evaluate your problem. For starters:
and if you are loading many images from device storage, you should consider using -[UIImage initWithContentsOfFile:]
instead because your image data would not be cached, but can be purged.
Upvotes: 2
Reputation: 38239
U need to use Lazy loading for images display as content will displayed as image gets downloaded.
Use SDWebImage which uses lazy loading of images.
Upvotes: 0