I have a function in my appDelegate that returns user's current location.
Now I want to call it asynchronously at some other place and I did:
func handleLocation() -> CLLocation {
let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
dispatch_async(dispatch_get_global_queue(priority, 0)) {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.startGPS()
while (!appDelegate.isLocationFixed()) {
sleep(1)
}
dispatch_async(dispatch_get_main_queue()) {
return appDelegate.getLocation()
}
}
}
but now this line return appDelegate.getLocation() brings me the error:
unexpected non-void return value in void function
I don't know too much about threads in Swift yet, could you help me with fixing this issue?