title: Swift: how to use UISwitch to control UITextField to be enabled or disabled with a delegate
body: <p>In <code>XCode 6.3.2</code>, I have a UITextField:</p>
  
  <pre><code>@IBOutlet weak var uiswitchControlledTextField: UITextField!
  </code></pre>
  
  <p>I am now using a UISwitch (named <code>mySwitch</code>) to control its enabled or disabled state in the following way:</p>
  
  <pre><code>@IBOutlet weak var mySwitch: UISwitch!
  mySwitch.addTarget(self, action: Selector("stateChanged:"), forControlEvents: UIControlEvents.ValueChanged)
  
  //callback below:
  func stateChanged(switchState: UISwitch) {
          uiswitchControlledTextField.enabled = switchState.on
  
      }
  </code></pre>
  
  <p>The above works well, however, I am looking to try if it would be possible to create a UITextFieldDelegate to control the above UITextField in the same way. So far, I have the following by implementing <code>textFieldShouldBeginEditing</code>, in which I wish to return false to disable the UITextField, but I don't know how to let the <code>UISwitch</code> dynamically return <strong>true</strong> or <strong>false</strong> from <code>textFieldShouldBeginEditing</code></p>
  
  <pre><code>import Foundation
  import UIKit
  
  class SwitchControlledTextFieldDelegate: NSObject, UITextFieldDelegate {
  
      func textFieldShouldBeginEditing(textField: UITextField) -&gt; Bool {
          return false; //do not show keyboard or cursor
      }
  
  }
  </code></pre>
  
  <p>In ViewController, I try to set</p>
  
  <pre><code>self.uiswitchControlledTextField.delegate = SwitchControlledTextFieldDelegate()
  </code></pre>
  
  <p>but it does not work as I wished. Any help would be appreciated.</p>