Reputation: 142
I'm still new to iOS and I have a problem here. I need to get data from api and when I get it i want to properly start my application. So, I have this code in appdelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
DispatchQueue.main.async {
let handler = APIHandler()
hand.getData(onSuccess: { (response) in
return true // CANT RETURN
}, onError: { (err) in
//SOMETHING ELSE HERE
})
}
return true // CAN RETURN
}
I just want to know how can I wait till my handler
finishes and return true
so i can start the application. Thanks in advance!
UPDATE: Thanks everyone. I decided to do everything in my splash screen. Didn't even think about it before :D
Upvotes: 0
Views: 1456
Reputation: 3415
You can't do it like that. Instead use a new viewController which shows a progress bar or any other loader (Better if it shows the view of splash screen). Once the data fetching is completed go to the first viewController
Upvotes: 2
Reputation: 58149
That is not the proper way to handle this. Use an initial view controller to handle network operations, show e. g. an activity indicator for the time the data is loading and proceed to the next screen in the handler block.
Upvotes: 2