Skip to content

Instantly share code, notes, and snippets.

@vaibhavgoyal09
Last active August 10, 2021 16:01
Show Gist options
  • Save vaibhavgoyal09/31788d888fdb40fa53ee7be4bfbb40fd to your computer and use it in GitHub Desktop.
Save vaibhavgoyal09/31788d888fdb40fa53ee7be4bfbb40fd to your computer and use it in GitHub Desktop.
override suspend fun getString(key: String): String? {
return try {
val preferencesKey = stringPreferencesKey(key)
val preferences = context.dataStore.data.first()
preferences[preferencesKey]
}catch (e: Exception){
e.printStackTrace()
null
}
}
override suspend fun getInt(key: String): Int? {
return try {
val preferencesKey = intPreferencesKey(key)
val preferences = context.dataStore.data.first()
preferences[preferencesKey]
}catch (e: Exception){
e.printStackTrace()
null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment