How to get rid of warning “Result of call 'resignFirstResponder()' is unused”?












2















Since I converted my code to Swift 3, I got a warning whenever I don't use the result of UITextField's resignFirstResponder() method.



enter image description here



There's no bugs ( at least for now ) but I don't really like to have warnings like that. So my questions:




  • Should I actually use the results of this kind of call ? And if the answer yes, what should I do with them ?

  • If the answer is no : how can I get rid of these warnings ?










share|improve this question



























    2















    Since I converted my code to Swift 3, I got a warning whenever I don't use the result of UITextField's resignFirstResponder() method.



    enter image description here



    There's no bugs ( at least for now ) but I don't really like to have warnings like that. So my questions:




    • Should I actually use the results of this kind of call ? And if the answer yes, what should I do with them ?

    • If the answer is no : how can I get rid of these warnings ?










    share|improve this question

























      2












      2








      2








      Since I converted my code to Swift 3, I got a warning whenever I don't use the result of UITextField's resignFirstResponder() method.



      enter image description here



      There's no bugs ( at least for now ) but I don't really like to have warnings like that. So my questions:




      • Should I actually use the results of this kind of call ? And if the answer yes, what should I do with them ?

      • If the answer is no : how can I get rid of these warnings ?










      share|improve this question














      Since I converted my code to Swift 3, I got a warning whenever I don't use the result of UITextField's resignFirstResponder() method.



      enter image description here



      There's no bugs ( at least for now ) but I don't really like to have warnings like that. So my questions:




      • Should I actually use the results of this kind of call ? And if the answer yes, what should I do with them ?

      • If the answer is no : how can I get rid of these warnings ?







      ios swift warnings






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 12 '16 at 11:58









      RandyRandy

      2,2621342




      2,2621342
























          3 Answers
          3






          active

          oldest

          votes


















          5














          As Shaggy D already said this warnings can be ignored safely.



          If you don't want to see them at all in your project you may set GCC_WARN_UNUSED_VALUE to false/NO in Build Settings.



          Or just add let _ = before resignFirstResponder():



          let _ = resignFirstResponder()





          share|improve this answer































            3














            1) You can ignore the result safely



            2) Put these lines before the call :



            #pragma clang diagnostic push
            #pragma clang diagnostic ignored "-Wunused-result"





            share|improve this answer
























            • #pragma? In Swift?

              – user28434
              Oct 12 '16 at 12:33











            • @user28434 Sure in swift ! You need to create .pch file add it to build settings and add there whatever and it works

              – Renetik
              Nov 23 '18 at 4:16





















            0














            resignFirstResponder will return false when the object you are asking to resign refuses to do so. For example, a text field will return false if it is in the middle of being edited, and I should imagine that the search bar in your example would do the same. If you ignore the result of these calls, therefore, you could get yourself into a bit of a mess.



            Warnings in XCode can be annoying, but my personal view is that they are generally helpful and you should edit your code to get rid of them. When I'm working on a load of new code I tend to accrue warnings but always clean them down regularly.



            In this situation I would advise you add some code to cover the eventuality of the search bar refusing to relinquish first responder status.



            Hope that helps.






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39998041%2fhow-to-get-rid-of-warning-result-of-call-resignfirstresponder-is-unused%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              5














              As Shaggy D already said this warnings can be ignored safely.



              If you don't want to see them at all in your project you may set GCC_WARN_UNUSED_VALUE to false/NO in Build Settings.



              Or just add let _ = before resignFirstResponder():



              let _ = resignFirstResponder()





              share|improve this answer




























                5














                As Shaggy D already said this warnings can be ignored safely.



                If you don't want to see them at all in your project you may set GCC_WARN_UNUSED_VALUE to false/NO in Build Settings.



                Or just add let _ = before resignFirstResponder():



                let _ = resignFirstResponder()





                share|improve this answer


























                  5












                  5








                  5







                  As Shaggy D already said this warnings can be ignored safely.



                  If you don't want to see them at all in your project you may set GCC_WARN_UNUSED_VALUE to false/NO in Build Settings.



                  Or just add let _ = before resignFirstResponder():



                  let _ = resignFirstResponder()





                  share|improve this answer













                  As Shaggy D already said this warnings can be ignored safely.



                  If you don't want to see them at all in your project you may set GCC_WARN_UNUSED_VALUE to false/NO in Build Settings.



                  Or just add let _ = before resignFirstResponder():



                  let _ = resignFirstResponder()






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 12 '16 at 12:40









                  user28434user28434

                  3,4621226




                  3,4621226

























                      3














                      1) You can ignore the result safely



                      2) Put these lines before the call :



                      #pragma clang diagnostic push
                      #pragma clang diagnostic ignored "-Wunused-result"





                      share|improve this answer
























                      • #pragma? In Swift?

                        – user28434
                        Oct 12 '16 at 12:33











                      • @user28434 Sure in swift ! You need to create .pch file add it to build settings and add there whatever and it works

                        – Renetik
                        Nov 23 '18 at 4:16


















                      3














                      1) You can ignore the result safely



                      2) Put these lines before the call :



                      #pragma clang diagnostic push
                      #pragma clang diagnostic ignored "-Wunused-result"





                      share|improve this answer
























                      • #pragma? In Swift?

                        – user28434
                        Oct 12 '16 at 12:33











                      • @user28434 Sure in swift ! You need to create .pch file add it to build settings and add there whatever and it works

                        – Renetik
                        Nov 23 '18 at 4:16
















                      3












                      3








                      3







                      1) You can ignore the result safely



                      2) Put these lines before the call :



                      #pragma clang diagnostic push
                      #pragma clang diagnostic ignored "-Wunused-result"





                      share|improve this answer













                      1) You can ignore the result safely



                      2) Put these lines before the call :



                      #pragma clang diagnostic push
                      #pragma clang diagnostic ignored "-Wunused-result"






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Oct 12 '16 at 12:04









                      Shaggy DShaggy D

                      2,75811330




                      2,75811330













                      • #pragma? In Swift?

                        – user28434
                        Oct 12 '16 at 12:33











                      • @user28434 Sure in swift ! You need to create .pch file add it to build settings and add there whatever and it works

                        – Renetik
                        Nov 23 '18 at 4:16





















                      • #pragma? In Swift?

                        – user28434
                        Oct 12 '16 at 12:33











                      • @user28434 Sure in swift ! You need to create .pch file add it to build settings and add there whatever and it works

                        – Renetik
                        Nov 23 '18 at 4:16



















                      #pragma? In Swift?

                      – user28434
                      Oct 12 '16 at 12:33





                      #pragma? In Swift?

                      – user28434
                      Oct 12 '16 at 12:33













                      @user28434 Sure in swift ! You need to create .pch file add it to build settings and add there whatever and it works

                      – Renetik
                      Nov 23 '18 at 4:16







                      @user28434 Sure in swift ! You need to create .pch file add it to build settings and add there whatever and it works

                      – Renetik
                      Nov 23 '18 at 4:16













                      0














                      resignFirstResponder will return false when the object you are asking to resign refuses to do so. For example, a text field will return false if it is in the middle of being edited, and I should imagine that the search bar in your example would do the same. If you ignore the result of these calls, therefore, you could get yourself into a bit of a mess.



                      Warnings in XCode can be annoying, but my personal view is that they are generally helpful and you should edit your code to get rid of them. When I'm working on a load of new code I tend to accrue warnings but always clean them down regularly.



                      In this situation I would advise you add some code to cover the eventuality of the search bar refusing to relinquish first responder status.



                      Hope that helps.






                      share|improve this answer




























                        0














                        resignFirstResponder will return false when the object you are asking to resign refuses to do so. For example, a text field will return false if it is in the middle of being edited, and I should imagine that the search bar in your example would do the same. If you ignore the result of these calls, therefore, you could get yourself into a bit of a mess.



                        Warnings in XCode can be annoying, but my personal view is that they are generally helpful and you should edit your code to get rid of them. When I'm working on a load of new code I tend to accrue warnings but always clean them down regularly.



                        In this situation I would advise you add some code to cover the eventuality of the search bar refusing to relinquish first responder status.



                        Hope that helps.






                        share|improve this answer


























                          0












                          0








                          0







                          resignFirstResponder will return false when the object you are asking to resign refuses to do so. For example, a text field will return false if it is in the middle of being edited, and I should imagine that the search bar in your example would do the same. If you ignore the result of these calls, therefore, you could get yourself into a bit of a mess.



                          Warnings in XCode can be annoying, but my personal view is that they are generally helpful and you should edit your code to get rid of them. When I'm working on a load of new code I tend to accrue warnings but always clean them down regularly.



                          In this situation I would advise you add some code to cover the eventuality of the search bar refusing to relinquish first responder status.



                          Hope that helps.






                          share|improve this answer













                          resignFirstResponder will return false when the object you are asking to resign refuses to do so. For example, a text field will return false if it is in the middle of being edited, and I should imagine that the search bar in your example would do the same. If you ignore the result of these calls, therefore, you could get yourself into a bit of a mess.



                          Warnings in XCode can be annoying, but my personal view is that they are generally helpful and you should edit your code to get rid of them. When I'm working on a load of new code I tend to accrue warnings but always clean them down regularly.



                          In this situation I would advise you add some code to cover the eventuality of the search bar refusing to relinquish first responder status.



                          Hope that helps.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Oct 12 '16 at 12:36









                          MarcusMarcus

                          1,1461617




                          1,1461617






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39998041%2fhow-to-get-rid-of-warning-result-of-call-resignfirstresponder-is-unused%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Costa Masnaga

                              Fotorealismo

                              Sidney Franklin