Reputation: 24912
I want to get rid of this compiler warning in just one file of my Xcode project. Is there a way to do this?
Upvotes: 4
Views: 4075
Reputation: 64012
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.";
Upvotes: 12