title: UserDefault Won't save data in tableView Swift 4
body: <p>I have been trying to save data when reloading app. However some how data won't save. </p>
  
  <pre><code>my global variable
  
  let defaults = UserDefaults.standard
  </code></pre>
  
  <p>this is my code on AddTaskView</p>
  
  <pre><code>@IBAction func addTask(_ sender: Any) {
  
      let date = datePicker.date
  
      let dateStr = dateFormatter.string(from: date)
  
      taskArray.append(selectedTask)
      dateArray.append(dateStr)
  
      defaults.set(selectedTask, forKey: "task")
      defaults.set(dateStr, forKey: "date")
  
      dismiss(animated: true, completion: nil)
  }
  </code></pre>
  
  <p>In my ViewController I have my viewWillApper</p>
  
  <pre><code>override func viewWillAppear(_ animated: Bool) {
      super.viewWillAppear(animated)
  
      defaults.string(forKey: "task")
      defaults.string(forKey: "date")
  
      tableView.reloadData()
  }
  </code></pre>
  
  <p>If I print the data coming back from AddTaskView It will print on console
  but data disappear when reloading app</p>
  
  <pre><code>tableView.dataSource = self (saved in my viewDidLoad)
  </code></pre>
  
  <p>this is my tableView </p>
  
  <pre><code>public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
      let cell = tableView.dequeueReusableCell(withIdentifier: "taskCell", for: indexPath)
  
      cell.textLabel?.text = "\(indexPath.row + 1). \(taskArray[indexPath.row])"
  
      cell.detailTextLabel?.text = dateArray[indexPath.row]
  
      return cell
  }
  </code></pre>
  
  <p>What Am I doing wrong?</p>
  
  <p>thanks</p>