title: How do I make a PHFComposeBarView control become active in a Swift iOS app?
body: <p>As a relative noob to iOS development I'm struggling to make a <a href="https://github.com/fphilipe/PHFComposeBarView" rel="nofollow noreferrer">PHFComposeBarView</a> control become active in my Swift iOS app.</p>
  
  <p>Having squinted at the Obj-C in the <a href="https://github.com/fphilipe/PHFComposeBarView/tree/master/Example" rel="nofollow noreferrer">PHFComposeBarView example app</a> and <a href="https://stackoverflow.com/a/26059637/171144">this SO answer</a>, I've managed as best I can to translate the basic setup into Swift such that the control is displayed in the main view:</p>
  
  <p><img src="https://i.stack.imgur.com/Fgejs.png" alt="enter image description here"></p>
  
  <p>However, I haven't managed to make the control become active programatically.</p>
  
  <p>I've created a <a href="https://github.com/liveminds/SwiftPHFComposeBarTest" rel="nofollow noreferrer">minimal test case project</a> in Swift 2.0/XCode 7.0 Beta 2 whose ViewController looks like:</p>
  
  <p>ViewController.swift:</p>
  
  <pre><code>import UIKit
  import PHFComposeBarView
  
  class ViewController: UIViewController, PHFComposeBarViewDelegate {
  
      var composeBar: PHFComposeBarView {
          let viewBounds = self.view.bounds
          let frame = CGRectMake(0.0, viewBounds.size.height - PHFComposeBarViewInitialHeight, viewBounds.size.width, PHFComposeBarViewInitialHeight)
          let composeBarView = PHFComposeBarView(frame: frame)
          composeBarView.delegate = self
          return composeBarView
      }
  
      override var inputAccessoryView: UIView {
          return self.composeBar
      }
  
      override func canBecomeFirstResponder() -&gt; Bool {
          return true
      }
  
      override func viewDidAppear(animated: Bool) {
          print("viewDidAppear self \(self)")
          print("composeBar.delegate \(self.composeBar.delegate)")
          print("composeBar.textView.delegate \(self.composeBar.textView.delegate)")
          print("composeBar.canBecomeFirstResponder() \(self.composeBar.canBecomeFirstResponder())")
          print("composeBar.textView.canBecomeFirstResponder() \(self.composeBar.textView.canBecomeFirstResponder())")
          let res = self.composeBar.becomeFirstResponder()
          print("composeBar.becomeFirstResponder() \(res)")
          print("composeBar.isFirstResponder() \(self.composeBar.isFirstResponder())")
          print("composeBar.textView.isFirstResponder() \(self.composeBar.textView.isFirstResponder())")
      }
  
  }
  </code></pre>
  
  <p>Console:</p>
  
  <pre><code>viewDidAppear self &lt;SwiftPHFComposeBarTest.ViewController: 0x7fe088619d90&gt;
  composeBar.delegate Optional(&lt;SwiftPHFComposeBarTest.ViewController: 0x7fe088619d90&gt;)
  composeBar.textView.delegate Optional(&lt;PHFDelegateChain: 0x7fe088654850&gt;)
  composeBar.canBecomeFirstResponder() true
  composeBar.textView.canBecomeFirstResponder() true
  composeBar.becomeFirstResponder() false
  composeBar.isFirstResponder() false
  composeBar.textView.isFirstResponder() false
  </code></pre>
  
  <p>How can it be that <code>composeBar.canBecomeFirstResponder()</code> returns <code>true</code> but <code>composeBar.becomeFirstResponder()</code> returns <code>false</code>? </p>
  
  <p>Also, I'm not sure if the delegate being an Optional is a problem.</p>
  
  <p><strong>EDIT: Updated to include debug output.</strong></p>