-
Notifications
You must be signed in to change notification settings - Fork 1.3k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
SharedState with UserDefaults(suiteName:) not working properly #3100
Comments
There is little bit of work to complete / verify in the Appstore Connect to be able to use App groups. Did you complete that? |
What kind of work are you referring to? Usually Xcode is taking care of updating the provisioning profile correctly, when you add the capability. |
@rcasula The third view is being instantiated like so: NavigationLink("Third view") {
ThirdView(store: .init(initialState: .init()) { Third() })
} This store is completely independent of the root store and doesn't share its dependencies unless you explicitly pass it along. If Alternately, if you require spinning up a new store you need to use extension UserDefaults {
static let mySuite = UserDefaults(
suiteName: "group.dev.casula.TCA.SharedStateShowcase"
)!
}
// ...
let store = Store(initialState: .init()) {
Home()
} withDependencies: {
$0.defaultAppStorage = .mySuite
}
// ...
ThirdView(store: .init(initialState: .init()) {
Third()
} withDependencies: {
$0.defaultAppStorage = . mySuite
} Because this is not a bug and just how TCA and user defaults work, I'm going to convert to a discussion. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Description
I'm trying to migrate an existing app to use the new SharedState functionality. My app uses an app group shared
UserDefaults
.When I set the
defaultAppStorage
dependency to be$0.defaultAppStorage = UserDefaults(suiteName: "..")
, I get some unexpected behaviour.Seems like if I use even
@Shared
or@SharedReader
in pushed views in a NavigationStack, doesn't update properly.This is the structure that I have:
Home with a
TabBar
and 3 tabs. Each tab has a button to present aSettings
screen with a sheet modal.The
Settings
screen has aNavigationStack
and pushes a new view ("ThirdView). The rootSettingsView
and theThirdView
contains aPicker
that changes the default tab that has to be selected upon opening the app.Using the
UserDefaults(suiteName: "..")
this happens:If I change the value in the root SettingsView everything works as expected. But if I do it in the ThirdView, the value is not even updated if I go back to the previous screen (which is the root SettingsView).
Using the UserDefaults.standard, everything works as expected.
This is an example project that showcases this weird behaviour: https://github.com/rcasula/TCASharedStateShowcase
Seems that trying a similar example with
@AppStorage
works.Checklist
main
branch of this package.Steps to reproduce
defaultAppStorage
dependency to either.standard
or theUserDefaults(suiteName: "..")
The Composable Architecture version information
1.10.4
Destination operating system
iOS 17
Xcode version information
15.3
Swift Compiler version information
The text was updated successfully, but these errors were encountered: