How can I get rid of an "unused variable" warning in Xcode? How can I get rid of an "unused variable" warning in Xcode? xcode xcode

How can I get rid of an "unused variable" warning in Xcode?


I'm unsure if it's still supported in the new LLVM compiler, but GCC has an "unused" attribute you can use to suppress that warning:

BOOL saved __attribute__((unused)) = [moc save:&error];

Alternatively (in case LLVM doesn't support the above), you could split the variable declaration into a separate line, guaranteeing that the variable would be "used" whether the macro expands or not:

BOOL saved = NO;saved = [moc save:&error];


Using Xcode 4.3.2 and found out that this seems to work (less writing)

BOOL saved __unused;


In Xcode you can set the warnings for "Unused Variables." Go to "Build Settings" for the target and filter with the word "unused"

Here is a screenshot: Builld Settings Screenshot

I suggest you only change it for Debug. That way you don't miss anything in your release version.