title: Switching the background color of view controller using a single button Xcode or swift
body: <p>The program is designed to have the screen toggle between black and white when the button is pressed. The problem is this is supposed to be accomplished with a button and not a switch. What is wrong with this code? When I run the program the background doesn't switch. Any suggestions on how to fix this issue?</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view.
         // set the background color to white when opened
          backgroundView.backgroundColor = .white
      }
  
      @IBOutlet weak var OnOffButton: UIButton!
      @IBOutlet var backgroundView: UIView!
      @IBAction func OnOff(_ sender: AnyObject) {
          // write your code here
          // code should change background color to black if it is white and vice versa. 
          if backgroundView.backgroundColor == .white {
              backgroundView.backgroundColor = .black
          } else {
              backgroundView.backgroundColor = .white
          }
  
      }
  
  }
  </code></pre>