Successfully reported this slideshow.
Your SlideShare is downloading. ×

AFNetworking

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 23 Ad

More Related Content

Slideshows for you (20)

Viewers also liked (20)

Advertisement

Similar to AFNetworking (20)

Advertisement

Recently uploaded (20)

AFNetworking

  1. 1. AFNetworking Houston iPhone Developers Meetup October 25th, 2011
  2. 2. 2 Who? • Full time contractiOSdeveloper out ofTheWoodlands • Contact me athttp://ipanemalabs.com • Founderof Houston iPhone Developers Meetup • Organizer of Houston PHP Users Group • Personal iPhone apps onstoresince 2008 • Personal site athttp://pessoal.org AFNetworking
  3. 3. 3 Tonight’s session • Overview of what AFNetworking provides • Background on the project • Alternatives to it • Bunch of code examples • Feel free to ask questions AFNetworking
  4. 4. 4 Background • Open-source library shared by Gowalla • Available at https://github.com/gowalla/AFNetworking • 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 license AFNetworking
  5. 5. 5 More background • Main authors very active behind the project • Mattt Thompson - http://mattt.me • Scott Raymond - http://scottraymond.net AFNetworking
  6. 6. 6 Alternatives • 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 - http://restkit.org • SVHTTPRequest - http://github.com/samvermette/SVHTTPRequest AFNetworking
  7. 7. 7 AFNetworking 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 request AFNetworking
  8. 8. 8 Installation • Clone AFNetworking github project • Copy “AFNetworking” sub-folder to your own Xcode project • Clone JSONKit github project • https://github.com/johnezang/JSONKit • Copy JSONKit.h and JSONKit.m to your own Xcode project AFNetworking
  9. 9. 9 Great documentation • Provides appledoc compatible documentation • Appledoc available at https://github.com/tomaz/appledoc • git clone https://github.com/tomaz/appledoc.git • sudo sh install-appledoc.sh • Installs on /usr/local/bin • git clone https://github.com/gowalla/AFNetworking.git • cd AFNetworking • appledoc -p AFNetworking -c "Gowalla" --company-id com.gowalla AFNetworking/*.h AFNetworking
  10. 10. 10 Documentation AFNetworking
  11. 11. 11 Blocks • 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 • http://developer.apple.com/library/ios/#documentation/cocoa/Conceptu al/Blocks/Articles/00_Introduction.html AFNetworking
  12. 12. 12 Blocks AFNetworking
  13. 13. 13 Core classes • Library core is AFURLConnectionOperation • NSOperation subclass to make asynchronous requests • Subclasses • AFJSONRequestOperation – JSON requests • AFXMLRequestOperation – XML requests • AFPropertyListRequestOperation – Plist requests • AFImageRequestOperation – Image requests AFNetworking
  14. 14. 14 JSON request • Dependency on JSONKit • Very high performance JSON library • Benchmark results available at https://github.com/johnezang/JSONKit • Claimed to be faster than parsing/serializing binary plists. • Results contested by TouchJSON author AFNetworking
  15. 15. 15 JSON request AFNetworking
  16. 16. 16 XML request • Similar to JSON request, but no automatic parsing of payload • Block callback allows you to kick off the XML parsing AFNetworking
  17. 17. 17 XML request AFNetworking
  18. 18. 18 Image 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 method AFNetworking
  19. 19. 19 Image request AFNetworking
  20. 20. 20 API 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 service implementation AFNetworking
  21. 21. 21 AFGowallaAPIClient AFNetworking
  22. 22. 22 More information • AFNetworking post on Gowalla’s Engineering blog • http://engineering.gowalla.com/2011/10/24/afnetworking/ • Github pages • Great information on issue list, network graph • Mattt’s profile page - https://github.com/mattt/ • TTTAttributedLabel - https://github.com/mattt/TTTAttributedLabel • FormatterKit - https://github.com/mattt/FormatterKit AFNetworking
  23. 23. Contact:

×