Johnny
09/25/2021, 12:39 AMSharedPreferences.Editor.()
I get the extension function is accepting a lambda with input SharedPreferences.Editor.()
but what does .()
mean?
private fun SharedPreferences.edit(func: SharedPreferences.Editor.() -> Unit) {
val editor = edit() // 1
editor.func() // 2
editor.apply() // 3
}
This is the code that uses the extension function
val sharedPref = requireActivity().getPreferences(Context.MODE_PRIVATE)
sharedPref.edit {
putBoolean("hello", true)
}
ephemient
09/25/2021, 1:33 AMJohnjake Talledo
09/26/2021, 4:30 PMfunc: sharedPreferences.Editor.() -> Unit