For example i made this function:
fun Context.prefs(f: SharedPreferences.() → Unit){
val preferences = getSharedPreferences(“prefs”, Context.MODE_PRIVATE)
preferences.f()
}
Now how to use it in code:
prefs {
var s = getString(“value”, “default value”)
}
//what if i need “s” outside this lambda? i have to put all the code inside prefs {}. Is there a way, besides making the variable “s” a nullable field in class?