I have a really common problem trying to create spinning activity indicator during an user authentication task with Firebase
I tried to use CGD dispatch_async but that doesn't seem to handle my issue. Here is my code
@IBAction func SignMeIn(sender: AnyObject) {
ActivityIndicator.hidden = false
ActivityIndicator.startAnimating()
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
NSLog("Before login func")
self.logIn()
dispatch_async(dispatch_get_main_queue(), { () -> Void in
NSLog("After login func")
self.ActivityIndicator.stopAnimating()
self.ActivityIndicator.hidden = true
})
});
}
func logIn(){
myRootRef.authUser(TXT_User.text, password: TXT_Password.text,
withCompletionBlock: { error, authData in
if error != nil {
NSLog(error.debugDescription)
} else {
NSLog("Connected !")
}
})
}
The thing is I surely do something wrong since in debug mode appears in this order :
"Before login func"
"After login func"
"Connected !"
Whereas I should have
"Before login func"
"Connected !"
"After login func"
What am I doing wrong please ? Thank you very much for your help :) !