The variable won't "never" be used.
connectionWithRequest:delegate:
doesn't actually start any networking. You must call the start
method on the variable before the connection is actually started. And after its been started, you can call the cancel
method on the variable to stop the connection.
EDIT: Per Rob's comment, connectionWithRequest:
and most of the NSURLConnection instantiation methods actually start the request. The variable is still returned though in case you want to cancel
(and there are probably other things you can do with it).
But if you never want to do anything with the variable after you initiate the connection, there are other ways to create a connection. I'll edit them in.
You can use sendAsynchronousRequest:queue:completionHandler:
, which returns void.
For this method, you send your request argument, and you give a queue for the connection to work on, and a block that is executed when the connection is done.
You can also do as Rob suggests and just not put the return value anywhere:
[NSURLConnection connectionWithRequest:request delegate:self];
If for whatever reason, you also don't like this, you can do this:
@autoreleasepool {
NSURLConnection *foo = [NSURLConnection connectionWithRequest:request delegate:self];
#pragma unused(foo)
}
Which I imagine will be optimized during compilation straight down to the previous example of just:
[NSURLConnection connectionWithRequest:request delegate:self];
As a note, #pragma unused(someVar)
will suppress unused variable warnings for the given variable.