Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

AFNetworking slides from my presentation at the October 2011 meeting of the Houston iPhone Developers Meetup.

Published in: Technology, Education
  • Be the first to comment


  1. 1. AFNetworking Houston iPhone Developers Meetup October 25th, 2011
  2. 2. 2Who?• Full time contractiOSdeveloper out ofTheWoodlands • Contact me at• Founderof Houston iPhone Developers Meetup• Organizer of Houston PHP Users Group• Personal iPhone apps onstoresince 2008• Personal site athttp://pessoal.orgAFNetworking
  3. 3. 3Tonight’s session• Overview of what AFNetworking provides • Background on the project • Alternatives to it• Bunch of code examples• Feel free to ask questionsAFNetworking
  4. 4. 4Background• Open-source library shared by Gowalla • Available at• Created in the development of Gowalla for iPhone • Inspired by an Apple sample project (MVC Networking)• Uses Objective-C blocks for everything (requires iOS 4+)• MIT licenseAFNetworking
  5. 5. 5More background• Main authors very active behind the project • Mattt Thompson - • Scott Raymond - http://scottraymond.netAFNetworking
  6. 6. 6Alternatives• ASIHTTPRequest • Convenience wrapper with lots of useful features • Author decided to stop maintaining it• NSURLConnection • Lots of tedious / boilerplate code to manage HTTP requests• Other options • RestKit - • SVHTTPRequest -
  7. 7. 7AFNetworking features• Uses NSOperation for scheduling and concurrency• Blocks for request completion / failure callbacks• Convenience features: • Requests for JSON, XML, Image data, etc • File upload with progress callback • API client requestAFNetworking
  8. 8. 8Installation• Clone AFNetworking github project• Copy “AFNetworking” sub-folder to your own Xcode project• Clone JSONKit github project •• Copy JSONKit.h and JSONKit.m to your own Xcode projectAFNetworking
  9. 9. 9Great documentation• Provides appledoc compatible documentation • Appledoc available at• git clone • sudo sh • Installs on /usr/local/bin• git clone • cd AFNetworking • appledoc -p AFNetworking -c "Gowalla" --company-id com.gowalla AFNetworking/*.hAFNetworking
  10. 10. 10DocumentationAFNetworking
  11. 11. 11Blocks• Closures for Objective-C • Similar in nature to JavaScript closures, but slightly different • Great for callback-centric code • Available since iOS 4 • Used a lot in Grand Central Dispatch (GCD)• Great introduction documentation available from Apple • al/Blocks/Articles/00_Introduction.htmlAFNetworking
  12. 12. 12BlocksAFNetworking
  13. 13. 13Core classes• Library core is AFURLConnectionOperation • NSOperation subclass to make asynchronous requests• Subclasses • AFJSONRequestOperation – JSON requests • AFXMLRequestOperation – XML requests • AFPropertyListRequestOperation – Plist requests • AFImageRequestOperation – Image requestsAFNetworking
  14. 14. 14JSON request• Dependency on JSONKit• Very high performance JSON library• Benchmark results available at • Claimed to be faster than parsing/serializing binary plists. • Results contested by TouchJSON authorAFNetworking
  15. 15. 15JSON requestAFNetworking
  16. 16. 16XML request• Similar to JSON request, but no automatic parsing of payload• Block callback allows you to kick off the XML parsingAFNetworking
  17. 17. 17XML requestAFNetworking
  18. 18. 18Image request• Load remote images on UIImageView asynchronously • Alternative to EGOImageView and similar libraries• Great on table view cells, async requests get canceled as cells are re-used• Simple interface to load images • -[UIImageView setImageWithURL:placeholderImage:] • More control available through a different methodAFNetworking
  19. 19. 19Image requestAFNetworking
  20. 20. 20API request• AFHTTPClient at the core • Detects appropriate operation for each request • AFGowallaAPIClient subclass of that• Easy to extend core class with the business logic for your own web serviceimplementationAFNetworking
  21. 21. 21AFGowallaAPIClientAFNetworking
  22. 22. 22More information• AFNetworking post on Gowalla’s Engineering blog •• Github pages • Great information on issue list, network graph• Mattt’s profile page - • TTTAttributedLabel - • FormatterKit -
  23. 23. Contact: