UISwitch set state
<p>I am working on an app, which has UISwitch. I want to set the switch to on/off programmatically. I tried it like so, but the switch is already turned on when <code>setting</code> is <code>false</code>... Any ideas?</p>

<pre><code>@IBOutlet var switch: UISwitch!

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    switch = UISwitch()

    if setting == true {
       switch.setOn(true, animated: false)
    } else {
       switch.setOn(false, animated: false)
    }
} 
</code></pre>

<p>the variable <code>setting</code> is not the problem.. I tested it out</p>