Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation about the force unwrap on a custom UserDefaults init. #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ for persisting your state. If you want to use a different user defaults, you can
@main struct EntryPoint: App {
init() {
prepareDependencies {
$0.defaultAppStorage = UserDefaults(suiteName: "co.pointfree.suite")
$0.defaultAppStorage = UserDefaults(suiteName: "co.pointfree.suite")!
}
}
// ...
}
```

That will make it so that all `@Shared(.appStorage)` instances use your custom user defaults.
The force unwrap on the `suiteName:` initializer will work if you do not use your app's main
bundle identifier or globalDomain.

In previews `@Shared` will use a temporary, ephemeral user defaults so that each run of the preview
gets a clean slate. This makes it so that previews do not mutate each other's storage and allows
Expand Down