let userDataIdentifier = "SavedUserData"
///*Saves UserData as codable in UserDefaults*
func saveUserData(userData: YOUR_MODAL) {
userDefault.set(try? PropertyListEncoder().encode(userData), forKey: userDataIdentifier)
}
///*Fetchs UserData as codable from UserDefaults*
func getUserData() -> YOUR_MODAL? {
if let data = userDefault.value(forKey: userDataIdentifier) as? Data {
return try? PropertyListDecoder().decode(YOUR_MODAL.self, from: data)
}
return nil
}
// YOUR_MODAL = Your Codable/Simple Structure or Class!