25

I'm sick to death of Xcode's prolific use of live "unused variable" warnings while I am typing. I keep thinking I have an error in my syntax, stop what I'm doing, check the warning, only to see it's an unused variable warning.

enter image description here

Of course it's unused, I just typed it!

I don't mind the compile-time unused variable warnings, those are very useful, but I hate the live warnings as I'm typing code.

Is there any way I can turn off this warning completely everywhere, either app-wide or for an entire project?

devios1
  • 36,899
  • 45
  • 162
  • 260
  • I advise you to ignore them. Even if you know why the warning is there, it doesn't mean it's not useful. Note that this IS a compile-time warning. The files get compiled while typing. – Sulthan Jan 21 '16 at 19:03
  • It must be possible to distinguish the types of compiles, though, and disable the warning only for IDE autoindex-type compiles. – Steven Fisher Jan 21 '16 at 19:05
  • 21
    I have an old MacBook you can buy. By the time it realises you haven't used the variable, you've typed the rest of the function. Problem solved. – jrturton Jan 21 '16 at 19:13
  • @StevenFisher Why? It's logical they both use exactly the same settings. – Sulthan Jan 21 '16 at 19:33
  • @Sulthan Why would you think that? If the doc compiler uses slightly different settings, why wouldn't the indexer? – Steven Fisher Jan 21 '16 at 21:30

2 Answers2

17

It seems as of currently, we cannot suppress specific warnings in the way #pragma clang diagnostic ... could be used for obj-C. See e.g. the following thread


There is possible to disable all interactive warnings globally, by disabling Show live issues, from Xcode -> Preferences: Tab General. This, however, in excess of disabling all live warnings, also disable live errors, so something I presume you wouldn't want to resort to.


[Build warnings] You can turn off custom build warnings project-wide as follows:

  • Select your project in the navigator, and choose tab Build Settings. Find Apple LLVM 7.0 - Warnings - All Languages, and disable the warnings for Unused Values and Unused Variables.

enter image description here

Community
  • 1
  • 1
dfrib
  • 70,367
  • 12
  • 127
  • 192
  • 6
    I think he's asking how to turn these off while typing only, not while building: "I don't mind the compile-time unused variable warnings, those are useful, but I HATE the live warnings as I'm typing code." – Steven Fisher Jan 21 '16 at 19:03
  • And unfortunately, even disabling this does not seem to affect the live warnings. – devios1 Jan 21 '16 at 19:08
  • I think dfri's is the only legal way possible. – Samraan Khaan Jan 21 '16 at 19:08
  • I realized this only affect build warnings, not the interactive ones. Don't know if it's possible to customly disable the latter ones. – dfrib Jan 21 '16 at 19:11
  • 1
    Current version of Swift (3.0) does not have toggleable warnings. Also not all of **Apple LLVM 7.0 - Warnings - All Languages** are implemented at all. That is why disabling or enabling them won't give any effect on Swift code. – Silmaril Oct 06 '16 at 15:17
  • 1
    @VyachaslavGerchicov this is an slightly older Q&A, and the answer covers XCode 7; Xcode 8 was yet to be released at the time of the question. I noticed that your total number of downvotes are the double amount of your total numbers of upvotes (very uncommon negative-reinforcement ratio). Consider bringing positive feedback to the answerers of the site (which answer by the own free good will), rather than wildly shooting downvotes at each and every answer you pass by. – dfrib Mar 27 '17 at 12:40
  • 2
    the only solution i found is to write ```_ = ...//some code with unused result``` - you can add it to your answer – Vyachaslav Gerchicov Mar 27 '17 at 12:47
2

On my version (Xcode 10.2.1), it seems as if disabling live warnings only disables warnings, not all errors as others have said. So, I would think this exact answer addresses the original post quite well:

Xcode > Preferences > General > Issues: [x] Show live issues

Uncheck "Show live issues". No more constant warnings as you type new code.

Steve Goldberg
  • 433
  • 6
  • 7