قالب وردپرس درنا توس
Home / IOS Development / My set of a structure stored with UserDefaults is not loaded when I add a new property to the structure. : iOSProgramming

My set of a structure stored with UserDefaults is not loaded when I add a new property to the structure. : iOSProgramming



I have a selection that stores instances of this structure:

  struct Person: Codable {
was name: String
was timeZone: TimeZone
var cityAndCountry: [String]
was unavailableDays: [String]
was selected: ClosedRange 
was beforeTime, posterity: TimeInterval
}

I had recently added was cityAndCountry: [String]. After I added it, the number of people already saved in my app couldn't be loaded.

  // To decode data from default values ​​for user with jsonDecoder
la default = UserDefaults.standard
if let savePeople = defaults.object (forKey: "people") as? Data {
la jsonDecoder = JSONDecoder ()
do {
people = try jsonDecoder.decode ([Person]. self, from: savedPeople)
} catch {
print ("Failed to load people.")
}
}

The decoding failed, and the message "Failed to load people." was printed. How can I adjust my code so that this doesn't happen every time I change my personal structure?


Source link