Pre-compiled header
open the pre-compiled header Weather-Prefix.pch from the Supporting Files section of the project. Add this line after the other imports:
#import "AFNetworking.h"
Adding AFNetworking to the pre-compiled header means that the framework will be automatically included in all the project’s source files.
Build Settings > Apple LLVM 6.0 - Language > Prefix Header : Weather/Weather-Prefix.pch
JSON easier
Note: FYI, an alternative way to make working with JSON results a bit easier than looking up keys in dictionaries or creating special categories like this is to use a third party library like JSONModel.
No XML
Hooking into the Live Service
AFHTTPSessionManager has everything you need to talk to a web API. It will decouple your networking communications code from the rest of your code, and make your networking communications code reusable throughout your project.
Here are two guidelines on AFHTTPSessionManager best practices:
- Create a subclass for each web service. For example, if you're writing a social network aggregator, you might want one subclass for Twitter, one for Facebook, another for Instragram and so on.
- In each AFHTTPSessionManager subclass, create a class method that returns a shared singleton instance. This saves resources and eliminates the need to allocate and spin up new objects.
Where To Go From Here?
Think of all the ways you can now use AFNetworking to communicate with the outside world:
- AFHTTPOperation with AFJSONResponseSerializer, AFPropertyListResponseSerializer, or AFXMLParserResponseSerializer response serializers for parsing structured data
- UIImageView+AFNetworking for quickly filling in image views
- Custom AFHTTPSessionManager subclasses to access live web services
- AFNetworkActivityIndicatorManager to keep the user informed
- AFHTTPOperation with a AFImageResponseSerializer response serializer for loading images
网友评论