Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

Fetch structure from 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 :: how to play a video in swift 
Swift :: get index filter swift 
Swift :: button in swiftui 
Swift :: how to download swift 
Swift :: swift rounded tab bar 
Swift :: how do i get a string from a float swift to 1 decimal swift 
Swift :: swift convert decimal to string 
Swift :: append new element to dictionary in swift 
Swift :: index string swift 
Swift :: dismiss two view controllers at once swift 
Swift :: string to double swift 
Swift :: swift url request 
Swift :: uiimage to data swift 
Swift :: swift add width height constraint to view without a lot of code 
Swift :: swift arrays 
Swift :: swift simulatore condition 
Swift :: ios make http request 
Swift :: remove key by index dictionary swift 
Swift :: case insensitive multiple word search swift 
Swift :: Swift Closures as Function Parameter 
Swift :: Function Inside Swift Struct 
Swift :: swift function declaration 
Swift :: variable sum in swift 
Swift :: Swift break with while Loop 
Swift :: Swift Change Value of Dictionary 
Swift :: multiline comment in swift 
Swift :: enums With Raw Values Swift 
Swift :: how to switch tabs in xcode 
Swift :: Swift guard with multiple conditions 
Swift :: bzxjhjgvjgvjgvjv 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =