Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

Save structure in userdefaults ios swift

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!
Comment

PREVIOUS NEXT
Code Example
Swift :: Save class in userdefaults ios swift 
Swift :: swift constraint center vertically 
Swift :: swiftui play mp3 
Swift :: swift dispatch after 
Swift :: generate random bool swift 
Swift :: swift doc comments 
Swift :: swiftui foreach 
Swift :: swiftui rectangle color 
Swift :: how to bold text swiftui 
Swift :: swift webview load html 
Swift :: swift date difference in days 
Swift :: swiftui background color 
Swift :: swift uitableview insert cell 
Swift :: swift add programmatically width height constraint to view 
Swift :: iOS & Swift - The Complete iOS App Development Bootcamp 
Swift :: standard bank swift code 
Swift :: uilabel make bold 
Swift :: rounded ios button 
Swift :: record permission swift 4 
Swift :: uilabel set font 
Swift :: swift create an empty dictionary 
Swift :: swift subtract dates 
Swift :: two variable sum in swift 
Swift :: swift arkit texture face get position on screen 
Swift :: xcode collapse cpde shortcut 
Swift :: Swift Named Tuple 
Swift :: Swift for vs while loop 
Swift :: Swift Operator Associativity 
Swift :: how to change the tint color of tab bar on storyboard swift 
Swift :: uicolor gray 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =