Nested callback function not working properly swift












1















I am trying to implement nested completion handlers but for some reason, my second handler is not firing upon completion. This is how the code looks like



//User presses a button on a cell. Code is in `cellForRowAtIndex...`
cell.callback = {
print("in CFRAIP")
self.showPopUpDialog(completionHandler: { () -> Void in
print("AfterPOPUPDIALOG")
self.requestBookingWithCompletionHandler(fetchBookingForDate: self.currentDate, row: indexPath.row)
})
}


func showPopUpDialog(completionHandler: () -> Void ){

print("In show PopUPdialog")

let alertController = UIAlertController(title: "Uppgifter", message: "Skriv in namn och telefonnummer", preferredStyle: .alert)

let confirmAction = UIAlertAction(title: "Boka", style: .default) { (_) in

//getting the input values from user
self.bokadNamn = (alertController.textFields?[0].text)!
self.bokadTelefon = (alertController.textFields?[1].text)!

print("pressed ok in popup")
}

let cancelAction = UIAlertAction(title: "Avbryt", style: .cancel) { (_) in}

//adding textfields to our dialog box
alertController.addTextField { (textField) in
textField.placeholder = "Namn"
textField.layer.cornerRadius = 5
}
alertController.addTextField { (textField) in
textField.placeholder = "Telefonnummer"
}

alertController.addAction(confirmAction)
alertController.addAction(cancelAction)

//finally presenting the dialog box
self.present(alertController, animated: true, completion: nil)
}


This is the prints that I am getting:



in CFRAIP
In show PopUPdialog
pressed ok in popup


print("AfterPOPUPDIALOG") is not being fired and my network request is not being run after the user pressed ok in the PopUP. I feel like it is something really simple that I am missing but unfortunately, I am to blind to see it...










share|improve this question





























    1















    I am trying to implement nested completion handlers but for some reason, my second handler is not firing upon completion. This is how the code looks like



    //User presses a button on a cell. Code is in `cellForRowAtIndex...`
    cell.callback = {
    print("in CFRAIP")
    self.showPopUpDialog(completionHandler: { () -> Void in
    print("AfterPOPUPDIALOG")
    self.requestBookingWithCompletionHandler(fetchBookingForDate: self.currentDate, row: indexPath.row)
    })
    }


    func showPopUpDialog(completionHandler: () -> Void ){

    print("In show PopUPdialog")

    let alertController = UIAlertController(title: "Uppgifter", message: "Skriv in namn och telefonnummer", preferredStyle: .alert)

    let confirmAction = UIAlertAction(title: "Boka", style: .default) { (_) in

    //getting the input values from user
    self.bokadNamn = (alertController.textFields?[0].text)!
    self.bokadTelefon = (alertController.textFields?[1].text)!

    print("pressed ok in popup")
    }

    let cancelAction = UIAlertAction(title: "Avbryt", style: .cancel) { (_) in}

    //adding textfields to our dialog box
    alertController.addTextField { (textField) in
    textField.placeholder = "Namn"
    textField.layer.cornerRadius = 5
    }
    alertController.addTextField { (textField) in
    textField.placeholder = "Telefonnummer"
    }

    alertController.addAction(confirmAction)
    alertController.addAction(cancelAction)

    //finally presenting the dialog box
    self.present(alertController, animated: true, completion: nil)
    }


    This is the prints that I am getting:



    in CFRAIP
    In show PopUPdialog
    pressed ok in popup


    print("AfterPOPUPDIALOG") is not being fired and my network request is not being run after the user pressed ok in the PopUP. I feel like it is something really simple that I am missing but unfortunately, I am to blind to see it...










    share|improve this question



























      1












      1








      1








      I am trying to implement nested completion handlers but for some reason, my second handler is not firing upon completion. This is how the code looks like



      //User presses a button on a cell. Code is in `cellForRowAtIndex...`
      cell.callback = {
      print("in CFRAIP")
      self.showPopUpDialog(completionHandler: { () -> Void in
      print("AfterPOPUPDIALOG")
      self.requestBookingWithCompletionHandler(fetchBookingForDate: self.currentDate, row: indexPath.row)
      })
      }


      func showPopUpDialog(completionHandler: () -> Void ){

      print("In show PopUPdialog")

      let alertController = UIAlertController(title: "Uppgifter", message: "Skriv in namn och telefonnummer", preferredStyle: .alert)

      let confirmAction = UIAlertAction(title: "Boka", style: .default) { (_) in

      //getting the input values from user
      self.bokadNamn = (alertController.textFields?[0].text)!
      self.bokadTelefon = (alertController.textFields?[1].text)!

      print("pressed ok in popup")
      }

      let cancelAction = UIAlertAction(title: "Avbryt", style: .cancel) { (_) in}

      //adding textfields to our dialog box
      alertController.addTextField { (textField) in
      textField.placeholder = "Namn"
      textField.layer.cornerRadius = 5
      }
      alertController.addTextField { (textField) in
      textField.placeholder = "Telefonnummer"
      }

      alertController.addAction(confirmAction)
      alertController.addAction(cancelAction)

      //finally presenting the dialog box
      self.present(alertController, animated: true, completion: nil)
      }


      This is the prints that I am getting:



      in CFRAIP
      In show PopUPdialog
      pressed ok in popup


      print("AfterPOPUPDIALOG") is not being fired and my network request is not being run after the user pressed ok in the PopUP. I feel like it is something really simple that I am missing but unfortunately, I am to blind to see it...










      share|improve this question
















      I am trying to implement nested completion handlers but for some reason, my second handler is not firing upon completion. This is how the code looks like



      //User presses a button on a cell. Code is in `cellForRowAtIndex...`
      cell.callback = {
      print("in CFRAIP")
      self.showPopUpDialog(completionHandler: { () -> Void in
      print("AfterPOPUPDIALOG")
      self.requestBookingWithCompletionHandler(fetchBookingForDate: self.currentDate, row: indexPath.row)
      })
      }


      func showPopUpDialog(completionHandler: () -> Void ){

      print("In show PopUPdialog")

      let alertController = UIAlertController(title: "Uppgifter", message: "Skriv in namn och telefonnummer", preferredStyle: .alert)

      let confirmAction = UIAlertAction(title: "Boka", style: .default) { (_) in

      //getting the input values from user
      self.bokadNamn = (alertController.textFields?[0].text)!
      self.bokadTelefon = (alertController.textFields?[1].text)!

      print("pressed ok in popup")
      }

      let cancelAction = UIAlertAction(title: "Avbryt", style: .cancel) { (_) in}

      //adding textfields to our dialog box
      alertController.addTextField { (textField) in
      textField.placeholder = "Namn"
      textField.layer.cornerRadius = 5
      }
      alertController.addTextField { (textField) in
      textField.placeholder = "Telefonnummer"
      }

      alertController.addAction(confirmAction)
      alertController.addAction(cancelAction)

      //finally presenting the dialog box
      self.present(alertController, animated: true, completion: nil)
      }


      This is the prints that I am getting:



      in CFRAIP
      In show PopUPdialog
      pressed ok in popup


      print("AfterPOPUPDIALOG") is not being fired and my network request is not being run after the user pressed ok in the PopUP. I feel like it is something really simple that I am missing but unfortunately, I am to blind to see it...







      swift completionhandler






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 10:49









      Damon

      5181318




      5181318










      asked Nov 24 '18 at 10:12









      Timo CengizTimo Cengiz

      2,02831330




      2,02831330
























          1 Answer
          1






          active

          oldest

          votes


















          2














          Inside the function func showPopUpDialog(completionHandler: () -> Void ) {, you are not calling the completion handler completionHandler anywhere.



          If you will not call your completion handler, how will print statement print("AfterPOPUPDIALOG") be executed?



          Call your completion handler completionHandler at the appropriate place.






          share|improve this answer


























          • Wow.. Haha i am really too tired. Thank you

            – Timo Cengiz
            Nov 24 '18 at 10:50











          • @TimoCengiz It happens :P .Please mark this as the accepted answer, if you think it helped you :D

            – Damon
            Nov 24 '18 at 10:51













          • I could not mark it before there was a time limit sorry :)

            – Timo Cengiz
            Nov 24 '18 at 16:06











          • Hey, thanks a lot :)

            – Damon
            Nov 24 '18 at 17:08











          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%2f53457127%2fnested-callback-function-not-working-properly-swift%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Inside the function func showPopUpDialog(completionHandler: () -> Void ) {, you are not calling the completion handler completionHandler anywhere.



          If you will not call your completion handler, how will print statement print("AfterPOPUPDIALOG") be executed?



          Call your completion handler completionHandler at the appropriate place.






          share|improve this answer


























          • Wow.. Haha i am really too tired. Thank you

            – Timo Cengiz
            Nov 24 '18 at 10:50











          • @TimoCengiz It happens :P .Please mark this as the accepted answer, if you think it helped you :D

            – Damon
            Nov 24 '18 at 10:51













          • I could not mark it before there was a time limit sorry :)

            – Timo Cengiz
            Nov 24 '18 at 16:06











          • Hey, thanks a lot :)

            – Damon
            Nov 24 '18 at 17:08
















          2














          Inside the function func showPopUpDialog(completionHandler: () -> Void ) {, you are not calling the completion handler completionHandler anywhere.



          If you will not call your completion handler, how will print statement print("AfterPOPUPDIALOG") be executed?



          Call your completion handler completionHandler at the appropriate place.






          share|improve this answer


























          • Wow.. Haha i am really too tired. Thank you

            – Timo Cengiz
            Nov 24 '18 at 10:50











          • @TimoCengiz It happens :P .Please mark this as the accepted answer, if you think it helped you :D

            – Damon
            Nov 24 '18 at 10:51













          • I could not mark it before there was a time limit sorry :)

            – Timo Cengiz
            Nov 24 '18 at 16:06











          • Hey, thanks a lot :)

            – Damon
            Nov 24 '18 at 17:08














          2












          2








          2







          Inside the function func showPopUpDialog(completionHandler: () -> Void ) {, you are not calling the completion handler completionHandler anywhere.



          If you will not call your completion handler, how will print statement print("AfterPOPUPDIALOG") be executed?



          Call your completion handler completionHandler at the appropriate place.






          share|improve this answer















          Inside the function func showPopUpDialog(completionHandler: () -> Void ) {, you are not calling the completion handler completionHandler anywhere.



          If you will not call your completion handler, how will print statement print("AfterPOPUPDIALOG") be executed?



          Call your completion handler completionHandler at the appropriate place.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 24 '18 at 10:39

























          answered Nov 24 '18 at 10:28









          DamonDamon

          5181318




          5181318













          • Wow.. Haha i am really too tired. Thank you

            – Timo Cengiz
            Nov 24 '18 at 10:50











          • @TimoCengiz It happens :P .Please mark this as the accepted answer, if you think it helped you :D

            – Damon
            Nov 24 '18 at 10:51













          • I could not mark it before there was a time limit sorry :)

            – Timo Cengiz
            Nov 24 '18 at 16:06











          • Hey, thanks a lot :)

            – Damon
            Nov 24 '18 at 17:08



















          • Wow.. Haha i am really too tired. Thank you

            – Timo Cengiz
            Nov 24 '18 at 10:50











          • @TimoCengiz It happens :P .Please mark this as the accepted answer, if you think it helped you :D

            – Damon
            Nov 24 '18 at 10:51













          • I could not mark it before there was a time limit sorry :)

            – Timo Cengiz
            Nov 24 '18 at 16:06











          • Hey, thanks a lot :)

            – Damon
            Nov 24 '18 at 17:08

















          Wow.. Haha i am really too tired. Thank you

          – Timo Cengiz
          Nov 24 '18 at 10:50





          Wow.. Haha i am really too tired. Thank you

          – Timo Cengiz
          Nov 24 '18 at 10:50













          @TimoCengiz It happens :P .Please mark this as the accepted answer, if you think it helped you :D

          – Damon
          Nov 24 '18 at 10:51







          @TimoCengiz It happens :P .Please mark this as the accepted answer, if you think it helped you :D

          – Damon
          Nov 24 '18 at 10:51















          I could not mark it before there was a time limit sorry :)

          – Timo Cengiz
          Nov 24 '18 at 16:06





          I could not mark it before there was a time limit sorry :)

          – Timo Cengiz
          Nov 24 '18 at 16:06













          Hey, thanks a lot :)

          – Damon
          Nov 24 '18 at 17:08





          Hey, thanks a lot :)

          – Damon
          Nov 24 '18 at 17:08




















          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%2f53457127%2fnested-callback-function-not-working-properly-swift%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

          Wiesbaden

          Marschland

          Dieringhausen