Skip to content

Instantly share code, notes, and snippets.

@florina-muntenescu
Created December 6, 2020 20:32
Show Gist options
  • Save florina-muntenescu/86194d49b607cf841bfa27d4fc5a32d0 to your computer and use it in GitHub Desktop.
Save florina-muntenescu/86194d49b607cf841bfa27d4fc5a32d0 to your computer and use it in GitHub Desktop.
// From https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:core/core-ktx/src/main/java/androidx/core/content/SharedPreferences.kt;l=39?q=SharedPreferences.kt
public inline fun SharedPreferences.edit(
commit: Boolean = false,
action: SharedPreferences.Editor.() -> Unit
) {
val editor = edit()
action(editor)
if (commit) {
editor.commit()
} else {
editor.apply()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment