Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

EasyUserDefaults

It's just a middleware for UserDefaults to write and read values by easy way

in default way to save the user name, we write this

letuserDefaults=UserDefaults.standard
// writing the value
userDefaults.set("Guest", forKey:"UserNameKey")
// reading the value
userDefaults.value(forKey:"UserNameKey")as?String

but using the subscripts, you can create the key and use it for write or read the value

letuserDefaults=UserDefaults.standard
letuserNameKey=UserDefaults.Key<String>("userNameKey", default:"Guest")
// reading the value letdefaultValue=userDefaults[.userNameKey]letnewValue="Jack"
// writing the value
userDefaults[.userNameKey]= newValue

and you can add more keys like this

extensionUserDefaults.Keys{staticletdidUserSeeSplash=Key<Bool>("didUserSeeSplash", default:false)staticletuserName=Key<String>("userName", default:"Guest")staticletcouterOfArticleSeen=Key<Int>("couterOfSeen", default:0)staticletpercentage=Key<Double>("couterOfSeen", default:0.0)}

About

Middleware to easily write and read from UserDefaults

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages