in kotlin is it more idiomatic to define a var* wi...
# announcements
w
in kotlin is it more idiomatic to define a var* with a custom getter and setter for persisting a value or defining methods for both to be explicit about the persistence going on
w
these aren't read only (you can change the value and hence cause persistence) so I don't know if those completely apply
d
`val`s can't have setters.
What do you mean by persistence? Like to a database or file?
w
yeah whoops. i meant a var
im in android land so im using shared preferences
d
Although it would kinda be idiomatic, persisting(calling
apply
) every
var
change wouldn't be ideal. You'll be better off with a DSL.
I'm assuming you have a class wrapping a
SharedPreferences
instance.
w
the setter of the
var
is calling apply. I don't have a class wrapping the shared preferences . what would you recommend that for? @Dominaezzz
d
I thought you were writing a type safe wrapper for
SharedPreferences
. If you're not, then calling
apply
in `setter is fine.
w
ok great! thanks