title: How To Store Data Permanently With User Defaults In xCode Swift for toggle button
body: <p>How can I save the state of my toggle button using userdefaults? Here is the code, please help me.</p>
  
  <pre><code>import UIKit
  
  
  class LawFigure: UIViewController {
  
  //Outlets:
  @IBOutlet weak var likeButton: UIButton!
  //Variables:
  
  var isButtonOn = false
  
  override func viewDidLoad() {
      super.viewDidLoad()
        customiseUI()
  
  }
  
  func customiseUI() {
  
      likeButton.layer.borderWidth = 3.0
      likeButton.layer.borderColor = UIColor(red: 0/255, green: 166/255, blue: 221/255, alpha: 1.0).cgColor
      likeButton.layer.cornerRadius = 20.0
      likeButton.clipsToBounds = true
  
  }
  @IBAction func followActionPressed(_ sender: Any) {
     self.activateButton(bool: !isButtonOn)
  }
  
  
      func activateButton(bool: Bool) {
  
      isButtonOn = bool
  
      likeButton.backgroundColor = bool ? UIColor(red: 0/255, green: 166/255, blue: 221/255, alpha: 1.0) : .clear
      likeButton.setTitle(bool ? "unlike": "like", for: .normal)
      likeButton.setTitleColor(bool ? .white : UIColor(red: 0/255, green: 166/255, blue: 221/255, alpha: 1.0), for: .normal)
  
  }
  
  
  }
  </code></pre>