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

swift userdefault fetch

UserDefaults.standard.bool(forKey: "Key")
 UserDefaults.standard.integer(forKey: "Key")
 UserDefaults.standard.string(forKey: "Key")
Comment

PREVIOUS NEXT
Code Example
Swift :: fetch codable from userdefaults ios swift 
Swift :: swift http request header 
Swift :: swift go back to previous view controller 
Swift :: prevent iphone to sleep swift 
Swift :: swift remove all duplicates from an array 
Swift :: swift clear user defaults 
Swift :: swift url encode string 
Swift :: swift set uicolor 
Swift :: swift dispatch queue 
Swift :: how to call app delegate function in swift 
Swift :: swift initialize a view 
Swift :: swift animate add subview 
Swift :: string to swift 2022 
Swift :: most frequent element in array swift 
Swift :: add navigation bar button swiftui 
Swift :: how to covert a string into a float in swift 
Swift :: add shadow to specific corner of UIView with shadow swift 6 site:stackoverflow.com 
Swift :: user defaults swift 
Swift :: uilabel set fon siz 
Swift :: swift uilabel dynamic height based on text length 
Swift :: replace back button image swift 
Swift :: delay code execution swift 4 
Swift :: two value sum 
Swift :: how to add dragdown gesture recognizer on view 
Swift :: UINavigationBar turns black 
Swift :: Swift Generic Function 
Swift :: Closure as function parameter 
Swift :: func collectionview 
Swift :: swift 5 uidatepicker display inline 
Swift :: swift uitextfield only numbers keyboard lock programmatically 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =