AFNetworking

8,748 views
8,576 views

Published on

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

Published in: Technology, Education
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,748
On SlideShare
0
From Embeds
0
Number of Embeds
521
Actions
Shares
0
Downloads
85
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

AFNetworking

  1. 1. AFNetworking Houston iPhone Developers Meetup October 25th, 2011
  2. 2. 2Who?• 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.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 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 licenseAFNetworking
  5. 5. 5More background• Main authors very active behind the project • Mattt Thompson - http://mattt.me • 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 - http://restkit.org • SVHTTPRequest - http://github.com/samvermette/SVHTTPRequestAFNetworking
  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 • https://github.com/johnezang/JSONKit• Copy JSONKit.h and JSONKit.m to your own Xcode projectAFNetworking
  9. 9. 9Great 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/*.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 • http://developer.apple.com/library/ios/#documentation/cocoa/Conceptu 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 https://github.com/johnezang/JSONKit • 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 • 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/FormatterKitAFNetworking
  23. 23. Contact:

×