Open jczerski opened 6 years ago
Does this really add much value? It causes allocation of varags and pairs for something that isn't much less verbose than the existing edit
-with-lambda approach. I'd rather figure out how to make the actions on the editor simpler if possible than something like this.
You are right, this is not the optimal solution. At the same time, pasting data due to their type is exhausting.
Regards, Jack
Instead you could have something an extension function on SharedPreferences.Editor
—put(key: String, val: Any?)
. This would do the type switch internally, with some special cases:
null
-> deletes instead of setting the keyWe'd do overloads. No need to switch.
On Mon, Feb 5, 2018, 6:56 PM Prateek Srivastava notifications@github.com wrote:
Instead you could have something an extension function on SharedPreferences.Editor —put(key: String, val: Any?). This would do the type switch internally, with some special cases:
- null -> deletes instead of setting the key
- non-SharedPreferences supported type -> throws an exception.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/android/android-ktx/issues/153#issuecomment-363262079, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEWTWNlfflftiVSL7Vb-tE4BePrg_ks5tR5UggaJpZM4R6Ph6 .
And delete is already remove("key")
which is hard to improve upon.
To my mind it would be nice to have some extension for setting many items to the SharedPreferences, something like this:
which does
Regards, Jack