title: Menu indexpath save UserDefaults swift
body: <p>I want to save whichever indexpath I last clicked in the menu. He's recording indexpath right now. But if I choose indexpath, he's recording it. If I don't choose, it doesn't. How can I keep the previous record even if I don't select item from the menu?</p>
  
  <pre><code>let save11 = UserDefaults.standard.integer(forKey: "indexPath")
  
          let yenindex = save11        
          self.menuView.setSelected(index: yenindex)    
          let userDefaults = UserDefaults.standard
          userDefaults.removeObject(forKey: "indexPath")
  
    menuView.didSelectItemAtIndexHandler = {(indexPath: Int) -&gt; Void in   
                  var placesdeger: String = ""
  
        UserDefaults.standard.setValue(indexPath, forKey: "indexPath")
  
                  if indexPath == 0 {
                      let userDefaults = UserDefaults.standard
                      userDefaults.removeObject(forKey: "indexPath")                    
     UserDefaults.standard.setValue(indexPath, forKey: "indexPath")
                      placesdeger = "Yatak Odası"
  
              }
                  if indexPath == 1 {
                      let userDefaults = UserDefaults.standard
                      userDefaults.removeObject(forKey: "indexPath")
  
            UserDefaults.standard.setValue(indexPath, forKey: "indexPath")
                      placesdeger = "Oturma Odası"
                      self.refreshData()
  
                  }
  </code></pre>