Do I need to wrap my Alamofire calls inside dispatch_async?

给你一囗甜甜゛ 提交于 2019-12-10 03:10:53

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/29552822/do-i-need-to-wrap-my-alamofire-calls-inside-dispatch-async

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!