title: Expected Declaration Error using Swift
body: <p>I'm trying to pass the boolean value of a <code>UISwitch</code> to another class using <code>NSUserDefaults</code>. For some reason, in the class that contains the switches, the <code>if</code> statements that are supposed to set the value to <code>NSUserDefaults</code> cannot read the switch declarations.</p>
  <h3>ViewController.swift</h3>
  <pre><code>@IBOutlet var shrimpSwitch: UISwitch!
  
  @IBOutlet var nutSwitch: UISwitch!
  
  @IBOutlet var dairySwitch: UISwitch!
  
  let switchState = NSUserDefaults.standardUserDefaults()
  
  
  if shrimpSwitch.switch.on{
  
      switchState.setBool(true, forKey: &quot;shrimpSwitch&quot;)
  }
  else{
  
      switchState.setBool(false, forKey: &quot;shrimpSwitch&quot;)
  }
  
  if nutSwitch.on{
  
      switchState.setBool(true, forKey: &quot;nutSwitch&quot;)
  }
  else{
  
      switchState.setBool(false, forKey: &quot;nutSwitch&quot;)
  }
  
  if dairySwitch.on{
  
      switchState.setBool(true, forKey: &quot;dairySwitch&quot;)
  }
  else{
  
      switchState.setBool(false, forKey: &quot;dairySwitch&quot;)
  }
  </code></pre>
  <p>In the first If statement(shrimpSwitch.on), it will say Expected Declaration. Am I declaring the switches all wrong? Any help would be appreciated. Thanks</p>