# SharedPreferencesKt

Added in 1.1.0

*** ** * ** ***


```
public final class SharedPreferencesKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final void` | `https://developer.android.com/reference/androidx/core/content/SharedPreferencesKt#(android.content.SharedPreferences).edit(kotlin.Boolean,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/SharedPreferences.html receiver, boolean commit, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/SharedPreferences.Editor.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> action )` Allows editing of this preference instance with a call to `https://developer.android.com/reference/android/content/SharedPreferences.Editor.html#apply()` or `https://developer.android.com/reference/android/content/SharedPreferences.Editor.html#commit()` to persist the changes. |

## Public methods

### edit

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/content/SharedPreferences.kt+function:edit) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static final void edit(
    @NonNull SharedPreferences receiver,
    boolean commit,
    @NonNull Function1<@NonNull SharedPreferences.Editor, Unit> action
)
```

Allows editing of this preference instance with a call to `https://developer.android.com/reference/android/content/SharedPreferences.Editor.html#apply()` or `https://developer.android.com/reference/android/content/SharedPreferences.Editor.html#commit()` to persist the changes. Default behaviour is `https://developer.android.com/reference/android/content/SharedPreferences.Editor.html#apply()`.

```
prefs.edit {
    putString("key", value)
}
```

To `https://developer.android.com/reference/android/content/SharedPreferences.Editor.html#commit()` changes:

```
prefs.edit(commit = true) {
    putString("key", value)
}
```