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 :: swift http request header 
Swift :: swift how to sort array 
Swift :: swiftui textfield multiline 
Swift :: How to Programatically Exit Flutter App 
Swift :: swift how to change the header color 
Swift :: swift email regex 
Swift :: swift how to animate constraint change 
Swift :: power number in swift13 
Swift :: swift 5 only the day number from date 
Swift :: swift replace all characters except numbers 
Swift :: clone repo using jenkins pipeline 
Swift :: porsche 
Swift :: NumberFormatter swift 
Swift :: custom tab bar swift ios 
Swift :: hide scroll view indicators bar swiftui 
Swift :: Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead. 
Swift :: swift get slected row data in tableview cell 
Swift :: swift change navigation bar title 
Swift :: declaring optionals swift 
Swift :: how to show notification icon on tabbar item swift 
Swift :: Swift for-in Loop 
Swift :: adding label to navigation bar 
Swift :: two variable sum 
Swift :: swift array in chunks 
Swift :: Swift Print Variables and Literals 
Swift :: uitableview total number of rows 
Swift :: swift UIColor to String 
Swift :: Autoclosure Swift 
Swift :: swift constraints 
Swift :: Swift Overriding Methods and Properties 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =