Get rid of the warning "Expression result is not used"
I have several lines of code:
NSURL *url = [NSURL URLWithString:URL];
NSURLRequest* request = [NSURLRequest requestWithURL:url .... ];
NSURLConnection* connection = [NSURLConnection alloc];
[connection initWithRequest:request delegate:self];
On the last line, I get an "Unused Expression Result" warning . Now, according to all the articles online I've read, this is the correct way to call the method and the syntax is recommended to load the async url. How can I rewrite this code to fix the warning?
source to share
#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
A list of all Clan warnings can be suppressed here
source to share
Replace the last 2 lines:
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
The warning is useful because it alloc
may return a different object than init
(for example, when you are using NSArray
that uses a class cluster template ).
In this case, it connection
will be a reference to this "intermediate" object returned alloc
instead of the fully initialized instance returned init
.
source to share