title: How can I check if a child view controller exists
body: <p>I am implementing a slide in style menu.</p>
  
  <p>The menu is added as a child view controller on show, then animated into view. I then remove it from the view once it has been closed.</p>
  
  <p>I would like to introduce a <code>UIPanGestureRecognizer</code> so the user can swipe it into view, however the logic for adding the view is only triggered when pressing open.</p>
  
  <p>I'd like to avoid adding it many times and on every gesture, so I was thinking of checking if it was present, if not add it, then animate.</p>
  
  <p>lazy var menuController = MenuController()</p>
  
  <pre><code>private var menuWidth: CGFloat = 300
  private let keyWindow = UIApplication.shared.keyWindow
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      setupNavigationItems()
      setupTableView()
  
      menuController.view.frame = CGRect(x: -menuWidth, y: 0, width: menuWidth, height: view.frame.height)
  
      let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan))
      view.addGestureRecognizer(panGesture)
  
  }
  
  @objc func handlePan(gesture: UIPanGestureRecognizer) {
  
  
      let translation = gesture.translation(in: view)
      let transform = CGAffineTransform(translationX: translation.x, y: 0)
      menuController.view.transform = transform
      navigationController?.view.transform = transform
  
  }
  
  @objc func handleOpen() {
      keyWindow?.addSubview(menuController.view)
      animateMenuController(transform: CGAffineTransform(translationX: self.menuWidth, y: 0)) { }
  
      addChild(menuController)
  
  }
  
  @objc func handleHide() {
      animateMenuController(transform: .identity) { [weak self] in
          self?.menuController.view.removeFromSuperview()
          self?.menuController.removeFromParent()
      }
  }
  </code></pre>
  
  <p>I was hoping to do something like this</p>
  
  <pre><code>    @objc func handlePan(gesture: UIPanGestureRecognizer) {
  
          if view.subviews.contains(MenuController) {
              print("yes")
          }
  
  
          let translation = gesture.translation(in: view)
          let transform = CGAffineTransform(translationX: translation.x, y: 0)
          menuController.view.transform = transform
          navigationController?.view.transform = transform
  
      }
  </code></pre>
  
  <p>But this is not correct.</p>