Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore "Unused Entity Issue: Unused Variable" in a single file

I want to get rid of this compiler warning in just one file of my Xcode project. Is there a way to do this?

like image 318
cfischer Avatar asked Dec 25 '22 22:12

cfischer


1 Answers

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.";
like image 193
jscs Avatar answered Dec 31 '22 14:12

jscs