I have the following few lines of code:
NSURL *url = [NSURL URLWithString:URL];
NSURLRequest* request = [NSURLRequest requestWithURL:url .... ];
NSURLConnection* connection = [NSURLConnection alloc];
[connection initWithRequest:request delegate:self];
In the last line I get "Expression Result Unused" warning. Now, according to all the articles online I have read, this is the correct way to call a method, and the syntax is as advised to download a URL async. How to rewrite this code to fix the warning?
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-value"
NSURL *url = [NSURL URLWithString:URL];
NSURLRequest* request = [NSURLRequest requestWithURL:url .... ];
NSURLConnection* connection = [NSURLConnection alloc];
[connection initWithRequest:request delegate:self];
#pragma clang diagnostic pop
For a list of all the Clang Warnings you can suppress take a look here
The problem comes from the fact that method NSURLRequest initWithRequest…
return an object that you don't store.
If you don't need it, you should write:
(void)[connection initWithRequest:request delegate:self];
On Xcode, you can use qualifier __unused
to discard warning too:
__unused [connection initWithRequest:request delegate:self];
to inform the compiler that you deliberately want to ignore the returned value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With