谁能帮助我理解这些问题:使用 Alamofire 优于 NSURLSession/NSURLConnection 有什么优势?
NSURLSession 和 NSURLConnection 有什么区别?
最佳答案
Alamofire 建立在 NSURLSession 之上,与 (POST/GET/PUT/etc) 进行 REST 交互的代码行数更少。它将为您提供“90%”的方法,但如果您需要进行 super 专业的网络调用,则需要使用 NSURLSession。
例如:获取 JSON 的简单 Alamofire 调用
Alamofire.request(.GET, "https://www.google.com/",encoding: .JSON).responseJSON {response in
if(response.result.error == nil){
print(response.data)
}else{
print("Network Error")
}
}
NSURLConnection 现在已被弃用,而 NSURLSession 是新标准。
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/UsingNSURLSession.html
关于nsurlconnection - 在 NSURLSession/NSURLConnection 上使用 Alamofire 进行网络有什么优势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36470840/