views:

479

answers:

1
NSURLResponse *response =[[NSURLResponse alloc] initWithURL:requestingURL
                                                   MIMEType:@"text/xml"
                                      expectedContentLength:-1
                                           textEncodingName:nil];

webData = [NSURLConnection sendSynchronousRequest:theRequest
                                returningResponse:response
                                            error:NULL];

I get the compiler warning saying warning pass argument from incompatible pointer type. I suspect this is because the NSURLResponse argument is a double star argument, (NSURLResponse **)?

What am I doing wrong here?

+8  A: 

The response is being returned to you by reference.

NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest: request
                                returningResponse: &response
                                error: &error];

This is the correct way to call it, and get back the response and error by reference.

In the code above, in addition to the syntax error, you're leaking the response object.

Jim Correia
Good answer. Note that it's completely legal to pass `NULL` for the error: parameter if you don't care to handle it, but it's generally good practice to get it by reference. Also, you shouldn't have to set `response` and `error` to nil before passing them, since the method will overwrite those values anyway. (There could be methods that don't, but IMO that's poor form. The least it can do is nil the arguments for you as appropriate.)
Quinn Taylor
Leaving uninitialized local variables lying around waiting to bite you is simply crazy.
Jim Correia
It will overwrite `error` if it has one to give you, but if it doesn't, it will leave `error` untouched. (Even if it doesn't leave it untouched, you still should assume it will, since what a method does to `error` in the case of no error is usually not documented.) Ostensibly, you should be able to rely on `error` being non-`nil` if `data` is `nil`, but remember Finagle's Law.
Peter Hosey