0

This is quite a simple yet perplexing problem. I have a UIBarButtonItem:

@IBAction func doneButtonPressed(_ sender: UIBarButtonItem) {
    guard let name = nameTextField.text,
               let estimatedHeight = estimatedHeightTextField.text,
               let locationDescription = descripitionTextView.text,
               let warnings = warningsTextView.text,
               let image = jumpSpotImageView.image else {
                   // notify user requred fields were blank
                   return
           }
           delegate?.createJumpSpotAnnotation(name: name, estimatedHeight: estimatedHeight, locationDescription: locationDescription, warnings: warnings, image: image)
           print("doneButton Pressed")
           dismiss(animated: true, completion: nil)
}

The code is quite irrelevant however. No matter what I try, the code will not execute once the button is clicked. I have redone the connection between the acutal BarButtonItem in the storyboard and the code several times, deleted it all and re-pasted it, restarted Xcode, etc etc. The circle next to the IBAction is full, and I have even put a print statement in the function to make sure my code wasn't just wrong. However the print statement doesn't even show up in the debugger, telling me the code isn't executing at all. Any idea what's wrong? This is so weird.

  • 1
    Have you tried putting the print statement before the `guard let` statement (or set a breakpoint on the first line) to ensure that the method is actually being called? It might be that one of the statements in your `guard let` is failing – Malik Aug 18 '20 at 00:40
  • @Malik That literally was it. I can't believe I didn't realize that. Thanks LOL –  Aug 18 '20 at 00:42
  • 1
    A fresh perspective always helps haha – Malik Aug 18 '20 at 00:45

1 Answers1

1

Because there is a guard let and it ensures that the name,estimatedHeight,locationDescription,warnings and image exist. If one of them is a nil, the following code will never be excuted.

Lynx
  • 381
  • 1
  • 13