Search code examples
iosasynchronousalamofirewatchkit

Watch Kit Asynchronus data


I am creating a simple watch kit app that shows me the local bus schedule. To get the schedules I have to make a request to the bus company's website and parse the HTML. (They have no public api....)

Alamofire is used to make a request and then parsing the HTML with SwiftySoup. The data is then saved into an array with structs and the table is created. Then the array is saved to a JSON file. So when the app is force closed and starts again, the app checks if the current time is past the first bus time, if true the app request the website again to get the next schedules otherwise it just creates the table with the number of schedules.

Since Alamofire is doing an asynchronous request, the app finishes "starting" even if it does not have any data. How can I "force" the app to wait for the request and parsing to be finished before displaying the UI?


Solution

  • As Josh Caswell mentioned it is not possible. So created UI for the loading state.

    If the app did not have any schedules cached or the cached data was old, the app pushed the loading interfacecontroller. When the loading was finished the interfacecontroller poped itself and the main interfacecontroller initilized with the corred UI.