title: How to save reorder of rows in TableView with Swift
body: <p>I search already a few days to the answer on the question how can I save the reorder TableView with Swift? So many tutorials on the internet show how to reorder but not how to save with UserDefaults.</p>
  
  <p>This is my code right now. What do I wrong?</p>
  
  <p>Please can you help me to the solution? Thank you very much.</p>
  
  <pre><code>import UIKit
  
  class soundboardTableViewController: UITableViewController {
  
      var list = ["January","February","March","April","May","June", "July","August","September","October","November", "December"]
  
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
  
          self.navigationItem.rightBarButtonItem = self.editButtonItem
  
          let blockItems = UserDefaults.standard.object(forKey:"soundboard")
  
          if(blockItems != nil) {
              list = blockItems as! [String]
          }
      }
  
  
      // MARK: - Table view data source
  
      override func numberOfSections(in tableView: UITableView) -&gt; Int {
          // #warning Incomplete implementation, return the number of sections
          return 1
      }
  
      override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          // #warning Incomplete implementation, return the number of rows
          return list.count
      }
  
  
      override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
  
          cell.textLabel?.text = list[indexPath.row]
  
          return cell
      }
  
  
      // Override to support conditional editing of the table view.
      override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -&gt; Bool {
          // Return false if you do not want the specified item to be editable.
          return true
      }
  
  
      /* Override to support editing the table view.*/
      override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
          if editingStyle == .delete {
              list.remove(at: indexPath.row)
  
              UserDefaults.standard.set(self.list, forKey:"soundboard")
              UserDefaults.standard.synchronize()
  
              tableView.reloadData()
          }
      }
  
      // Override to support rearranging the table view.
      override func tableView(_ tableView: UITableView, moveRowAt indexPath: IndexPath, to: IndexPath) {
          let itemToMove = list[indexPath.row]
          list.remove(at: indexPath.row)
          list.insert(itemToMove, at: indexPath.row)
  
          UserDefaults.standard.set(self.list, forKey:"soundboard")
          UserDefaults.standard.synchronize()
      }
  
      override func setEditing(_ editing: Bool, animated: Bool) {
          super.setEditing(editing, animated: animated)
  
          if(self.isEditing) {
  
          }
      }
  
  
      // Override to support conditional rearranging of the table view.
      override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -&gt; Bool {
          // Return false if you do not want the item to be re-orderable.
          return true
      }
  
  
  
      // MARK: - Navigation
  
      // In a storyboard-based application, you will often want to do a little preparation before navigation
      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
          // Get the new view controller using segue.destinationViewController.
          // Pass the selected object to the new view controller.
      }
  
  
  }
  </code></pre>