문제

I am new to iOS programing.

I have a requirement where I have to do server calls many times giving large JSON and then parsing and showing in TableView/Collection/View Controllers.

And I have to download Images inside Collection Grid View and UITableView, thereby starting/cancelling downloading of images on user scrolling.

So

Q1) For image downloading in Table View/Grid View I am thinking to use Apple Table Lazy Loading Sample + replacing Icon Downloader with that of SDWebImage as mentioned here in link several problem in that Apple sample and via SDWebImage I can config cache as per my requirement.

EDIT: Basically I would like to have a very transparent way to get images from a url, so first look for them in a NSCache, if not found look on disk (or Core Data)l if not found again download async and then again save in cache as well.I guess SDWebImage provides this but for AFNetworking i have to look inside code and modify it.

iOS lazy-loading of table images

Q2) For server calls and JSON parsing, whether I should go for using dispatch_async and then parse JSON using NSJSONSerialization or I should go for using AFNetworking for this

Disadvantage of using AFNetworking lib is that I need only server call and parsing no other functionality..and for this reason if I would be going for this lib this would increase app size by 1.4 MB as I am already adding SDWebImage framework (>3 MB).

This is what I found after lot of googling. Please suggest if I am missing something...and any other approach I should follow.

도움이 되었습니까?

해결책

AFNetworking is better and can handle your both problems. You can also use it for parsing as well as for image download. It can cache even and will never go to server again and again if same image is requested by an image view. Use UImageView category provided in AFNetworking.

Edit Caching in Afnetworking read posts in this submisison. If you don't want to use full functionality of AFNetworking and just want to download data, I wills suggest you don't use it, You can do this all with NSURSession, Don't add dependency in your project. Use NSURLSession its strong an can do better for you. YOu just need only one NSJSONSerilization call to parse data to NSObject, that is not to big deal.

NSURLSessionDataTask *task = [session dataTaskWithRequest:request
                                         completionHandler:
     ^(NSData *data, NSURLResponse *response, NSError *error) {
         // ...
     }];

 [task resume];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top