So as has been generally conventional among the plugged in set we’ve been using ASIHTTPRequest for our heavy lifting network needs the last while, but it seems that teh tweeties are all abuzz lately with a new contender for that job:
Well, those are rather enthusiastic sounding, aren’t they? So what is this AFNetworking thingy then?
A delightful iOS networking library with NSOperations and block-based callbacks
There’s a lot to be said for a networking library that you can wrap your head around. API design matters, too. Code at its best is poetry, and should be designed to delight (but never surprise).
AFNetworking was lovingly crafted to make best use of our favorite parts of Apple’s Foundation framework: NSOperation for managing multiple concurrent requests, NSURLRequest & NSHTTPURLResponse to encapsulate state, NSCache & NSURLCache for performant and compliant cacheing behavior, and blocks to keep request / response handling code in a single logical unit in code.
If you’re tired of massive libraries that try to do too much…
If you’ve taken it upon yourself to roll your own hacky solution…
If you want a library that actually makes iOS networking code kinda fun…
…try out AFNetworking.
Never thought we’d see “networking code” and “kinda fun” in a concatenation. And we have spent waaaaaaay too much of our lives in writing it, that being pretty much the first task everyone finds obvious to delegate to THE MAC GUY on a cross-platform team, we have found. But why yes, the samples do look like pretty nice simple code, and integrated nicely with JSONKit too. So as long as you can require a minimum of iOS 4 for the blocks, which is rapidly approaching “not a problem” status for new projects, that does indeed look worth a look.
Bonus: The acknowledgements led us to FormatterKit, which looks like quite the handy addition to your bag of tricks as well:
FormatterKit is a collection of well-crafted NSFormatter subclasses for things like hours of operation, distance, and relative time intervals. Each formatter abstracts away the complex business logic of their respective domain, so that you can focus on the more important aspects of your application.
In short, use this library if you’re manually formatting any of the following (with string interpolation or the like):
Arrays: Display NSArray elements in a comma-delimited list (eg. “Russell, Spinoza & Rawls”)
Hours of Operation: Format and collapse recurring weekly business hours (eg. “Mon-Wed: 8:00AM – 7:00PM”)
Location, Distance & Direction: Show CLLocationDistance, CLLocationDirection, and CLLocationSpeed in metric or imperial units (eg. “240ft Northwest” / “45 km/h SE”)
Ordinal Numbers: Convert cardinal NSNumber objects to their ordinal in most major languages (eg. “1st, 2nd, 3rd” / “1ère, 2ème, 3ème”)
Time Intervals: Show relative time distance between any two NSDate objects (eg. “3 minutes ago” / “yesterday”)
URL Requests: Print out cURL or Wget command equivalents for any NSURLRequest (eg. curl “https://api.gowalla.com/spots/” -H “Accept: application/json”
Code you don’t have to write is always the best kind!
Woah! Yep, it is officially, from the author, time to stop using ASIHTTPRequest as active development has ended. His suggestions for where to look forward:
From the people who make Gowalla. A general purpose HTTP lib, built on modern patterns, actively developed. AFNetworking has been gaining a lot of traction over the last few months, so it’s a good bet that it’s going to be around for a while.
A lightweight HTTP lib, actively developed. Also comes in an ARC-flavoured variety.
For applications that talk to REST-based services, lets you map remote objects and store them in CoreData. It sounds like this could replace a lot of code in the right circumstances.
AWS SDK for iOS
Amazon S3 support has been one of the most popular ASIHTTPRequest features. These days Amazon offers their own SDK for iOS, providing access to S3, CloudFront, SimpleDB and other Amazon cloud services.
The highest-level API listed here. Provides a simple way to upload content to a variety of services, and a UI to make it super easy to drop into your projects.
From the people who make your cellphone. Built by smart people, lightweight, actively developed.
SVHTTPRequest is another simple, fast, blocks, etc. option stressing straightforwardness.
Or try Introducing MKNetworkKit + Advanced Networking with MKNetworkKit.
Another MKNetworkKit vote: ASIHTTPRequest is dead, now what?
And RSOAuthEngine is a lean Twitter implementation for MKNetworkKit.
Say hello to FSNetworking: A Small Networking Library for iOS and Mac
AFNetworking / AFNetworking-ASIHTTPRequest eases the transition.
iOS AFNetworking Add-On Library That Provides Accelerated Downloading
OliverLetterer / AFURLConnectionByteSpeedMeasure “is a drop in extension for AFNetworking to measure download and upload speed of an AFURLConnectionOperation and estimate completion times.”
jboehler / AYNetworking “is a set of category with API methods to make it easier to handle requests and response with AFNetworking Framework.”
AFNetworking Crash Course
jaminguy / JGAFImageCache “A fast reliable image cache for iOS built with AFNetworking.”
The Minus Sign: “The default behavior of NSNumberFormatter is to use the hyphen-minus to format negative numbers … your text will look much more professional if you use the real minus sign.”
Alamofire / Alamofire : Elegant Networking in Swift
Alamofire Tutorial Part 1: Getting Started and Part 2: Progress and Caching
SwiftyJSON; Nice Web Services, Swift Edition; Working with JSON in Swift Tutorial; Parsing JSON APIs with SwiftyJSON
grok.swift.com tutorial series:
UITableView Tutorial in Swift using Alamofire, Haneke and SwiftyJSON and UICollectionView version
Continue Reading →