1

I am parsing data from a web api. A get a huge list of items and tableview takes 30 seconds to load and display the list. I tried append, but append takes time to load too. What is the efficient way to do this?

let url = "http://sampleapi.com/list"
Alamofire.request(.GET, url).responseJSON { (Request, response, json, error) -> Void in
    if (json != nil){
        var jsonObj = JSON(json!)
        if let jsonResults = jsonObj["items"].arrayValue as [JSON]?{
            self.itemList = jsonResults
            self.tableView.reloadData()
serdar aylanc
  • 1,307
  • 2
  • 20
  • 37
  • I think the best way is to create an asynchronous request for each cell, so when the cell is displayed, you request the data for this cell (which is in an instance), and then displays the data as soon as it gets loaded. – Dejan Skledar Aug 17 '15 at 20:52
  • I think the network call is already async and it's hanging at `if let jsonResults = ...` because it's doing lots of data transformation on the main thread. Try adding a bunch of `print(NSDate())` calls to your code to find the slow spot. Then consider moving it to a background thread as explained in http://stackoverflow.com/a/25070476/354144 – Neal Ehardt Aug 17 '15 at 22:11
  • thank you, moving background did the work... – serdar aylanc Aug 18 '15 at 15:23

0 Answers0