Closed saikishoreagrapalem closed 6 years ago
There are various ways to handle async code. When you search for articles you can find a lot about it. See for instance: https://medium.com/ios-os-x-development/managing-async-code-in-swift-d7be44cae89f and https://medium.com/@zhxnlai/async-programming-in-swift-with-asynctask-95a708c1c3c0
In your case the question is if you already have a reference somewhere to your view controller. If so, then just add a public property to that view controller and assign the data to it. Maybe through a function so that you could change the UI depending on the data. If you don't have a reference to the viewcontroller or if it's uncertain if the reference is already available, then you need to save the data somewhere so that the viewconroller can access it (on present or so).
Usually when data from a network call is needed in multiple view controllers you will execute that call outside the view controller. For instance from a network layer where you could also subscribe to changes of the returned data. Then both your initial screen and your other view controller could subscribe to the data and you will start the data fetch from the first.
one other thing. The code below your 'print(model)' access the UI. I assume that your network call is executed on a background thread. You should execute UI changes on the main thread. You can use DispatchQueue.main.async { .. }
for that.
// Network calling for first screen and getting response and setting in to the model.
RTWebService.sharedInstance.webServiceInitialGETCall(url: "/api/CurrentLocationandNews?ostype=ios&latitude=(curentLat)&longitude=(curentLong)&secretcode=$3cr3t&appv=1.0.0", paramValues: [
// Model
class RTModel: NSObject {
}
class CommonObjects: EVObject {
}
public class Transaction: EVObject {
}
// now I want to use this same response in the another view controller class file. please help me for this same ?? @evermeer