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?
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()
}
}
The deprecated code with the error is the following 2 lines:
let encodedData = NSKeyedArchiver.archivedData(withRootObject: scores)
let scoreList = NSKeyedUnarchiver.unarchiveObject(with: data) as? [Int] {