Add null-safe SharedPreferences.getStringSafe
Null-safe alternative to SharedPreferences.getString that guarantees the return value is non-null when defValue is non-null.
This commit is contained in:
parent
94f992a2e2
commit
734b6e2b67
2 changed files with 12 additions and 6 deletions
|
|
@ -0,0 +1,7 @@
|
|||
package org.schabi.newpipe.ktx
|
||||
|
||||
import android.content.SharedPreferences
|
||||
|
||||
fun SharedPreferences.getStringSafe(key: String, defValue: String): String {
|
||||
return getString(key, null) ?: defValue
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue