I want to get rid of this compiler warning in just one file of my Xcode project. Is there a way to do this?
You can turn off specfic warnings in Clang using a pragma directive and the "diagnostic" keyword, like so:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
// Insert code here
#pragma clang diagnostic pop
No unused variable warnings will be produced for the code between the push and the pop.
A second option, even more targeted, is to mark a particular variable with a GCC-style attribute, specifically, "unused". Clang honors GCC's established attributes and won't issue a warning about that one variable:
__attribute__((unused))
NSString * thisStringIsJustForFun = @"It's only work if somebody makes you do it.";
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