Replies: 4 comments 4 replies
-
There is little bit of work to complete / verify in the Appstore Connect to be able to use App groups. Did you complete that? |
Beta Was this translation helpful? Give feedback.
-
What kind of work are you referring to? Usually Xcode is taking care of updating the provisioning profile correctly, when you add the capability. |
Beta Was this translation helpful? Give feedback.
-
@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 them 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
} |
Beta Was this translation helpful? Give feedback.
-
Hi @stephencelis, thanks for your input. Indeed you are right, I was instantiating the Third view without a reference to the parent store, of course this wouldn't work. Fixed it in the sample project. I believe I found another hint: In my real world project, The settings feature has its own NavigationStack, with StackStore navigation; I ported this scenario in the sample project. ....et voilà, here it is the same issue. When instantiating the Is it the Third.State initializer that is causing the issue? Keep in mind that using |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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
Beta Was this translation helpful? Give feedback.
All reactions