Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the advantage of using Alamofire over NSURLSession/NSURLConnection for networking?

Tags:

Can anyone help me in understanding these question : What is the advantage of using Alamofire over NSURLSession/ NSURLConnection?

What are the differences between NSURLSession and NSURLConnection?

like image 816
Srikanth Adavalli Avatar asked Apr 07 '16 08:04

Srikanth Adavalli


People also ask

What is the advantage of Alamofire?

Alamofire makes developing networking layers easier, faster and much cleaner. Another great benefit of using it is that it can be studied and its code is available. This can help programmers because it's a well-written framework.

Does Alamofire use URLSession?

Alamofire does not support URLSession s configured for background use.

What is Alamofire software?

Alamofire is an elegant, open source HTTP networking library written in Swift. It gives you an elegant interface on top of Apple's URL loading system provided by the Foundation framework.


1 Answers

NSURLConnection is Apple's old API for doing networking (e.g. making HTTP requests and receiving responces), while NSURLSession is their new one. The latter one is higher level and is generally much easier and involves less boilerplate code to use for most application developers - there's basically no reason to use the former except in legacy code that you don't want to update.

A bit of history: Before NSURLSession came out, a third party library, AFNetworking, became the de facto standard for doing networking in Objective C, as it provided an easier and more convenient API than NSURLConnection (which it was a wrapper around - I think these days it wraps NSURLSession instead). The same developer later made a similar library for Swift, called AlamoFire in order to fully take advantage of "the Swift way of doing things" (instead of just adding Swift bindings to AFNetworking). Around the same time NSURLSession came out and it seemed pretty obvious that Apple had been inspired by AFNetworking and wanted to make their new networking API just as convenient to work with - by and large I think they succeded. What this means is that while previously, using AFNetworking instead of NSURLConnection was the only sane choice for most developers, today the advantages of using AFNetworking or AlamoFire over NSURLSession are much smaller, and for most developers starting up new projects I'd recommend to just start by using NSURLSession and only look into AlamoFire if they feel that they run into some limitation or inconvenience that is big enough to justify adding another dependency.

like image 200
Martin Gjaldbaek Avatar answered Oct 12 '22 17:10

Martin Gjaldbaek