Asynchronous communication over swift

Asked 2 years ago, Updated 2 years ago, 39 views

I am currently developing an app, and I would like to pass the current location information (latitude, longitude) and current time to the API as URL parameters, but it doesn't work.

A: Class to retrieve current location
B:Current time class
C: Class to retrieve data from API

I would like to instantiate the above three classes (A, B, C) in ViewControllr and call them A, B, and C in viewDidload(), but as far as debugging is concerned, I cannot get data from the API because I cannot pass the location information as parameters.
Is there a good way to process in the order of A, B, and C?
I would appreciate it if you could let me know.

swift

2022-09-30 20:50

1 Answers

This means that the processing of A is asynchronous, but I want to synchronize it.As long as you use Apple's asynchronous processing procedures, it's contraindicated to wait for the ABC to complete in viewDidLoad because it blocks the main thread (UI) processing.
 You can start A in viewDidLoad.

Therefore, in order to wait for the completion of A's processing, use NSNotification or completion handler, and after A's completion, it is not viewDidLoad.You have to call B and C.


2022-09-30 20:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.