Download images from NSURL async using RestKit

Is there a shell in RestKit or some built-in functions for loading a UIImage from NSURL asynchronously using callbacks or blocks? I could not find such a method in RestKit . If not, is there a good strategy to implement lazy loadable asynchronous images from NSURL using RestKit as much as possible?

+6
source share
2 answers

Using RestKit, you can use RKRequest to load data for an image in a way like:

 RKRequest* request = [RKRequest requestWithURL: url]; request.onDidLoadResponse = ^(RKResponse* response) { UIImage* image = [UIImage imageWithData: response.body]; // do something interesting with the image }; request.onDidFailLoadWithError = ^(NSError* error) { // handle failure to load image } [imageLoadingQueue addRequest: request]; 

Note that even with onDidLoadResponse you can check response to make sure the data type is as expected. The image download queue used above can be created as follows:

 imageLoadingQueue = [RKRequestQueue requestQueueWithName: @"imageLoadingQueue"]; [imageLoadingQueue start]; 
+5
source

Not sure about RestKit solution, but SDWebImage is a library that allows you to easily load images asynchronously by adding a category to UIImageView, so all you need to write is (for example):

 [myImageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 
+19
source

Source: https://habr.com/ru/post/911266/


All Articles