uchicago-mobi / MPCS51030-2017-Winter-Forum

7 stars 0 forks source link

updating a View Controller #177

Open turabhassan89 opened 7 years ago

turabhassan89 commented 7 years ago

I have a simple view controller and after downloading the data I need to update the view controller based on the data that was downloaded but I have been able to figure out how to do a tableview.reloaddata() equivalent in a simple view controller.

I have code setup like this:

           print("starting to parse data")
            sharedNetworking.sharedInstance.downloadDataBusiness() { (fromDownload) in
            print("ready to parse")
            self.parseData (dataDownloaded: fromDownload)
        }
        print("parsing done")

But the first and third print statement always print first. I have also tried to put the code on the main thread and also in viewwillAppear function but it is not working. I have pushed my code for this as well.

tabinks commented 7 years ago

This is the correct behaviors. The first and third will execute first since they are on the same thread. The second will only fire once the network call is done.

turabhassan89 commented 7 years ago

So what I am trying to do here is to download the data and after downloading parse it and save it and then do a lookup. I am able to download it and parse correctly but the lookup function tries for a lookup before the data is parsed. Does this mean that I need a completion handler within a completion handler? One for downloading the data(which I have right now) and one for parsing the data. How will I go about writing that?

sharedNetworking.sharedInstance.downloadDataBusiness() { (fromDownload) in
            print("ready to parse")
            self.parseData (dataDownloaded: fromDownload)
        }
        doALookup()