Created
March 19, 2021 16:01
-
-
Save adammagana/676d38e2b4aa4f5fab2fd98a2ffbf80b to your computer and use it in GitHub Desktop.
An Android SharedPreferences function extension that simplifies the edit-and-apply flow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.SharedPreferences | |
/** | |
* Simple extension to remove the need to call `SharedPreferences.edit()` and `SharedPreference.Editor.apply()` for | |
* every preferences change. | |
*/ | |
fun SharedPreferences.update(updateBlock: SharedPreferences.Editor.() -> Unit) { | |
val editor = edit() | |
updateBlock(editor) | |
editor.apply() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment