title: Swift; delegate embedded view controller and parent
body: <p>Sorry in advance that I can’t explain myself very well. I’m really new to programming and the topic of delegation still eludes me. I had some great <a href="https://stackoverflow.com/questions/31710691/performing-function-from-a-different-class-with-swift/31712999?noredirect=1#comment51367571_31712999">help</a> with this once before, but now I am trying to use a delegate in a different situation and I can’t get it right. I pieced together a bit of code that doesn’t work, and no matter how much I search I can’t find a way to fix it. </p>
  
  <p>I have a view controller (MainController) with and embedded view controller (EmbeddedController) in a container view. I am trying to have a button in the embedded controller manipulate the container view (containerView).</p>
  
  <p>EmbeddedController:</p>
  
  <pre><code>protocol ControllerDelegate {
      func hideContainerView()
  }
  
  class EmbeddedController: UIViewController {
      var delegate: VControllerDelegate?
  
      @IBAction func button(sender: AnyObject) {
      delegate?.hideContainerView()
      }
  }
  </code></pre>
  
  <p>MainController:</p>
  
  <pre><code>class MainController: UIViewController, ControllerDelegate {
  
      @IBOutlet var containerView: UIView!
  
      func hideContainerView() {
      containerView.hidden = true
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
          var vc = EmbeddedController()
          vc.delegate = self
      }
  }
  </code></pre>
  
  <p>Does anyone have any idea what I am doing wrong? And why this isn’t working? </p>