Struggling to understand this. Does anyone know wh...
# android
j
Struggling to understand this. Does anyone know what the syntax at line 2 means? And why the input is
SharedPreferences.Editor.()
I get the extension function is accepting a lambda with input
SharedPreferences.Editor.()
but what does
.()
mean?
Copy code
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
Copy code
val sharedPref = requireActivity().getPreferences(Context.MODE_PRIVATE)
sharedPref.edit {
    putBoolean("hello", true)
}
j
its a lambda
func: sharedPreferences.Editor.() -> Unit