What does registerHTTPOperationClass do in AFNetworking?

I am trying to understand how the AFNetworking Framework works. But I donโ€™t understand the little things.

I wrote a subclass of AFHTTPclient , which made it a single class and added an initializer that does the following:

 - (id)initWithBaseURL:(NSURL *)url { self = [super initWithBaseURL:url]; if (self) { [self registerHTTPOperationClass:[AFJSONRequestOperation class]]; } return self; } 

I got this code from a tutorial that I found on the Internet, but I donโ€™t understand why I need to register my class for JSONRequestOperation if I want to return JSON Data? What exactly happens under the hood if I do this? What does the registerHTTPOperation class do?

PS: Is there any good documentation with examples and detailed explanations of AFNetworking somewhere on the Internet?

+6
source share
1 answer

registerHTTPOperationClass: in AFHTTPclient will use a set of classes to process the request when using the getPath and postPath methods.

In this example, HTTPRequestOperation is set to AFJSONRequestOperation , which means that the entire server request will be executed with an AFJSONRequestOperation instance. AFJSONRequestOperation will try to AFJSONRequestOperation result from the server using the NSJSONSerialization class.

If the server is responding to XML, you should set HTTPRequestOperation AFXMLRequestOperation , for example.

+11
source

All Articles