Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to wrap my Alamofire calls inside dispatch_async?

func authenticate(completion:(success: Bool) -> Void) {
let qos = Int(QOS_CLASS_USER_INITIATED.value)
dispatch_async(dispatch_get_global_queue(qos, 0)){ () -> Void in
    Alamofire.request(.POST, CONSTANTS.Domain+"/accounts", parameters: ["" : ""]).responseJSON { (req, res, json, error)  in
         dispatch_async(dispatch_get_main_queue()){
               completion(success: true)
         }
    }
}
}

Or, can I leave out the dispatch and just keep my code simple?

like image 714
TIMEX Avatar asked Apr 10 '15 03:04

TIMEX


1 Answers

Alamofire is designed to be asynchronous. On another note, if the method has as callback, most likely it is asynchronous. So, yes you can leave out the dispatch_async calls.

like image 194
Schemetrical Avatar answered Sep 28 '22 02:09

Schemetrical