         }
     }
 }
+
+fileprivate extension UIView {
+    
+    enum Anchor {
+        case Top
+        case Bottom
+    }
+    
+    func attach(anchor: Anchor, to view: UIView) {
+        
+        translatesAutoresizingMaskIntoConstraints = false
+        
+        if #available(iOS 9, *) {
+            
+            switch anchor {
+            case .Top:
+                topAnchor.constraint(equalTo: view.topAnchor).isActive = true
+            case .Bottom:
+                bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
+            }
+            
+            leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
+            rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
+            
+        } else {
+            
+            switch anchor {
+            case .Top:
+                NSLayoutConstraint(item: self, attribute: .top, relatedBy: .equal, toItem: view, attribute: .top, multiplier: 1.0, constant: 0).isActive = true
+            case .Bottom:
+                NSLayoutConstraint(item: self, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1.0, constant: 0).isActive = true
+            }
+            
+            // left anchor
+            NSLayoutConstraint(item: self, attribute: .left, relatedBy: .equal, toItem: view, attribute: .left, multiplier: 1.0, constant: 0).isActive = true
+            // right anchor
+            NSLayoutConstraint(item: self, attribute: .right, relatedBy: .equal, toItem: view, attribute: .right, multiplier: 1.0, constant: 0).isActive = true
+        }
+    }
+}

    var consoleWindowMode: TinyConsoleWindowMode = .collapsed {
        didSet {
            consoleViewHeightConstraint?.isActive = false
            consoleViewHeightConstraint?.constant = consoleWindowMode == .collapsed ? 0 : 140
            consoleViewHeightConstraint?.isActive = true
        }
    }
    
    public init(rootViewController: UIViewController) {
        self.rootViewController = rootViewController
        super.init(nibName: nil, bundle: nil)

        setupConstraints()
    }
    
    func setupConstraints() {
        
        guard let rootViewControllerView = rootViewController?.view else {
            print("You forgot to setup the rootViewController for TinyConsole")
            return
        }
        
        rootViewControllerView.attach(anchor: .Top, to: view)
        
        consoleViewController.view.attach(anchor: .Bottom, to: view)
        consoleViewHeightConstraint?.isActive = true
        
        if #available(iOS 9, *) {
            
            rootViewController?.view.bottomAnchor.constraint(equalTo: consoleViewController.view.topAnchor).isActive = true
        } else {
            
            NSLayoutConstraint(item: (rootViewController?.view)!, attribute: .bottom, relatedBy: .equal, toItem: consoleViewController.view, attribute: .top, multiplier: 1.0, constant: 0).isActive = true
        }
