title: Use return value from modal view controller in iOS
body: <p>I have a subclassed UIView that looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/e9JwS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e9JwS.png" alt="item selector"></a></p>
  
  <p>ItemSelector:</p>
  
  <pre><code>class ItemSelector: UIView {
      weak var delegate: ItemSelectorDelegate?
      // ...
      func addButtonPressed(button: UIButton) {
          // called when "+" button is pressed
          let confirmed = delegate?.addItemOrNot() // delegate function
          if confirmed! { /* update ui */ }
      }
  }
  </code></pre>
  
  <p>MainViewController:</p>
  
  <pre><code>class MainViewController: UIViewController, ItemSelectorDelegate {
      @IBOutlet weak var itemSelector: ItemSelector!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          itemSelector.delegate = self
      }
  
      func addItemOrNot() -&gt; Bool {
          performSegueWithIdentifier("AddOrNot", sender: self)
          return ??? // results from modal view controller
      }
  }
  </code></pre>
  
  <p>When the "+" button is pressed, a modal view controller containing "Yes"/"No" buttons will show. If the user selects "Yes", the addItemOrNot() function will return true; else it returns false, and the view will remain unchanged. I've already wired the controllers up with segues.</p>
  
  <p>How can I return a boolean value depending on which button I press in the modal view controller? And how can I use the returned value in the addItemOrNot() function?</p>