Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does registerHTTPOperationClass in AFNetworking actually do? [closed]

I am trying to understand how the AFNetworking Framework works. But there is little detail I do not understand.

I wrote a subclass of AFHTTPclient than made it a singleton class and added a 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 I found on the internet, but I do not understand why I have to register my class for JSONRequestOperation if I want to get JSON Data back? What exactly happens under the hood if I am doing so? What does the registerHTTPOperation class exactly do?

PS: Is there a good documentation with examples and in-depth explanations of AFNetworking somewhere on the internet?

like image 780
Sebastian Boldt Avatar asked Dec 17 '12 09:12

Sebastian Boldt


1 Answers

The registerHTTPOperationClass: on AFHTTPclient will use the class set to handle you request when using the getPath and postPath methods.

In your given example, the HTTPRequestOperation is set the the AFJSONRequestOperation, which means that all request to the server will be done with an instance of AFJSONRequestOperation. The AFJSONRequestOperation will try and parse the result from the server with the NSJSONSerialization class.

If you server responds with XML you should set the HTTPRequestOperation to AFXMLRequestOperation for example.

like image 50
rckoenes Avatar answered Sep 19 '22 00:09

rckoenes