title: archive and unarchive data: SWIFT 4
body: <p>I have the following code. It's been deprecated and gives me that yellow warning. I want that to go away. Any thoughts on how to fix this?</p>
  
  <pre><code>var linearScore = 0
  var spreadScore = 0
  
  
  func saveScores () {
      print("SAVE START")
      let scores : [Int] = [linearScore, spreadScore]
      let encodedData = NSKeyedArchiver.archivedData(withRootObject: scores)
      UserDefaults.standard.set(encodedData, forKey: "scores")
  }
  
  func retrieveScores () {
      print("Scores being retrieved")
  
      //comment out the if/let below to reset goals in dev
  
      if let data = UserDefaults.standard.data(forKey: "scores"),
          let scoreList = NSKeyedUnarchiver.unarchiveObject(with: data) as? [Int] {
  
          self.linearScore = scoreList[0]
          self.spreadScore = scoreList[1]
  
          self.updateTopScores()
  
      } else {
          print("There is an issue")
          self.saveScores()
      }
  }
  </code></pre>
  
  <p>The deprecated code with the error is the following 2 lines:</p>
  
  <p>let encodedData = NSKeyedArchiver.archivedData(withRootObject: scores)</p>
  
  <p>let scoreList = NSKeyedUnarchiver.unarchiveObject(with: data) as? [Int] {</p>