1

I'm hoping someone can help me understand all the differences at large between the latest version of AFNetworking (at the time of this writing, v2.4.1) and NSURLSession in the context of iOS 8.

I'm not super savvy when it comes to doing this kind of study because I tend to have a hard time discerning what is actually a pro and how that pro can add value to the development process for a team.

I've used AFNetworking in a previous project and enjoyed it. I really do want to make a case for it as an alternative to NSURLSession but some people really don't like having a 3rd-party dependency that has the potential of breaking down the road (an inevitable truth for a lot of developers out there).

I've heard people saying that AFNetworking 2 fills "a lot of the gaps" that NSURLSession currently has (UIKit extensions? SSL Pinning? Built-in reachability? Are those examples?). Can anyone further elaborate on what exactly those gaps are? And leveraging NSURLCache in both those implementations -- is there anything different between the two?

Also, does AFNetworking 2.4 use NSOperation and NSOperationQueue under the hood for all NSURLSessionDataTasks that get fired off via AFURLSessionManager/AFHTTPSessionManager? (for asynchronous optimizations and such)

esqew
  • 42,425
  • 27
  • 92
  • 132
Danchez
  • 1,266
  • 2
  • 13
  • 28
  • Why not just [look at the source code](https://github.com/AFNetworking/AFNetworking) if you wanna know how it works "under the hood"? – esqew Oct 27 '14 at 15:21
  • I did look at the source code, but I still have trouble developing and conveying an answer as to why it's something that should be leveraged as opposed to natively using NSURLSession. Again, I haven't fully developed the mental ability to see the nuances of the AFNetworking implementation that provide the value of usage I want to communicate in concise verbal terms -- something I'm hoping someone can help with. I have little to no experience in using NSURLSession (except through AFNetworking) which is why if someone has used both and can identify the limitations, I'd love to hear them. – Danchez Oct 27 '14 at 15:30
  • 1
    I believe the JSON parsing is easier with AFNetworking – noobsmcgoobs Nov 08 '14 at 07:38
  • @noobsmcgoobs Really appreciate your input. That much is known, but I think it's really just eliminating the boilerplate, one-line `NSJSONSerialization` instruction that converts NSData to an NSDictionary no? Because unfortunately, that's not enough of a point to really make a case for using AFNetworking over `NSURLSession`. There has to be some other optimization to shed light on. Here's a thought though, would people make an argument to say that AFNetworking is more readable? Those helper GET and POST AFHTTPSessionManager methods do make things pretty clear when you're sight reading as a dev – Danchez Nov 17 '14 at 22:02
  • 1
    @DanielSanchez I guess but it's really the JSON parsing. JSON parsing is a pain in the ass, but then the rest of NSURLSession is more transparent and more customizable. You're pick - easier JSON parsing vs. more transparency basically. I'm sure there are other details, but that's about 80% of it. – noobsmcgoobs Nov 18 '14 at 01:09
  • @noobsmcgoobs Hmmm...can you elaborate when you say JSON parsing is a pain? I mean, parsing it is just using that single `NSJSONSerialization` method call (`+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error`) that converts the `NSData` response from `NSURLSession`'s `dataTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler` into an NSDictionary no? – Danchez Nov 19 '14 at 17:20
  • @DanielSanchez I don't know man, I just use AFNetworking. You just set the property and don't even need a method call. You put the return in a variable and you're good to go. The UIKit extensions are cool and easy. Don't know what else to say. Go with what works for you. Not relying on an external framework helps keep things clearer IMO. I just used AF in my project because that's what I learned, if I had learned the other way, I'd probably do it that way. – noobsmcgoobs Nov 20 '14 at 02:02

0 Answers0