4 Replies
      Latest reply: Feb 13, 2017 4:49 PM by Macho Man Randy Savage RSS
      Macho Man Randy Savage Level 3 Level 3 (315 points)

        If I'm just typing a variable out like:

         

        var someURLs = Array<URL>()
        

         

        I get a compiler warning, with a suggestion that will change the code to:

         

        _ = Array<URL>()
        

         

        I just typed it out, I'm about to use the variable in a couple of seconds, so I really don't want to use the suggested fix.

         

        In Objective-C we get a warning, which is useful so you don't forget, but don't get hinted to do something we don't want to do.

         

        The compiler seems pretty aggressive in trying to get you to fix things, making suggestions that make no sense because you are still writing the code?

        • Re: Unused Variable Warning in Swift Suggested Fix Is a Bit Annoying?
          eskimo Apple Staff Apple Staff (7,180 points)

          I recommend you file a bug about this.  It’s a complex UI issue — you want issues to show to show up quickly, but not too quickly — and it’d be good for you to register you opinion on how that balance should be struck.

          Please post your bug number, just for the record.

          btw This issue has been the subject of an interesting swift-evolution conversation recently.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: Unused Variable Warning in Swift Suggested Fix Is a Bit Annoying?
              Macho Man Randy Savage Level 3 Level 3 (315 points)

              Cool. Thanks for the info. I'll have to file a bug on this later. The issue described on that linked page is pretty much how I was feeling.

               

              There were some suggestions by the compiler, like the unused variable suggestion that I felt for the most part were unnecessary (suggesting to do something that is only "correct" from the compiler's perspective but the compiler doesn't have enough context to make such a decision b/c  I'm still typing).

               

              I have a habit of taking the suggested fixes in ObjC because the compiler is usually right. In some cases I think it'd probably be enough to just leave the warning with no suggested fix.