https://kotlinlang.org logo
#android
Title
# android
o

Ofir Bar

02/23/2020, 11:31 AM
Hi all, I made a code that returns a
User
object from the Shared Preferences. Here is the line of code I use:
Copy code
private val mCurrentUser = Defaults[PrefsKeys.user]!!
So
Defaults[PrefsKeys.user]!!
returns the current
User
object stored in Shared Preference. The issue is when I change the value in the Shared Preference,
mCurrentUser
is still the same
User
object. Can I replace
mCurrentUser
to be an actual call to the SharedPreference? I guess I am trying to make something like an alias. Because calling Defaults[PrefKeys.user]!! everytime is not very readable.
t

Tolriq

02/23/2020, 11:56 AM
don't use = but get() =
o

Ofir Bar

02/23/2020, 12:06 PM
thank you! 🙂 @Tolriq
4 Views