The following code is returning an expression unused warning on the assignment operation in the block. The code isn't very practical, but there is a lot more code in the excluded section and that code has to run on a particular queue.
__block NSNumber *pageId=nil;
dispatch_sync(_myDispatchQueue, ^{
int val;
//... code generates an int and puts it in val
pageId = [NSNumber numberWithInt:val];
}];
//pageId used below
How do I get rid of this error?
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-value"
pageId = [NSNumber numberWithInt:val];
#pragma clang diagnostic pop
Note I got this from Intrubidus, but I wanted additional information so after experimenting I recorded my findings here for the next guy.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-value"
pageId = [NSNumber numberWithInt:val];
#pragma clang diagnostic pop
Only applies to the area between the ignore and the pop. "-Wunused-value" does not suppress unused variables.
This is how you would suppress unused variables:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
int i = 0;
#pragma clang diagnostic pop
Also, without the push and pop, as shown:
#pragma clang diagnostic ignored "-Wunused-value"
pageId = [NSNumber numberWithInt:val];
The type of warning was ignored anywhere in that file after the #pragma. This seems to only apply to the file in question.
Hope you found this useful,
- Chase
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