我需要将我的Alamofire调用包装在dispatch_async中吗? [英] Do I need to wrap my Alamofire calls inside dispatch_async?

查看:116
本文介绍了我需要将我的Alamofire调用包装在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?

推荐答案

Alamofire旨在实现异步。另一方面,如果该方法具有回调,则很可能是异步的。
所以,是的,你可以省去dispatch_async调用。

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.

这篇关于我需要将我的Alamofire调用包装在dispatch_async中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆