Replies: 4 comments 3 replies
-
|
The state variable has to exist within a SwiftUI hierarchy. Right now your observable handler object is stored in the There's a few ways to address this, but what I'd recommend is installing the I've copied your code and done a few modifications to achieve the expected behavior. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the comment, @orchetect. I tried your example and it worked, however once I tried to replicate in my own project the following error is thrown: I'm not really sure why it happens or what could differ. |
Beta Was this translation helpful? Give feedback.
-
|
Likely be because the project template I used has MainActor isolation enabled by default in the build settings. If not already, make sure your class is bound to @MainActor class CallbackHandler: ObservableObject { /* ... */ } |
Beta Was this translation helpful? Give feedback.
-
|
I re-built the test app without MainActor isolation enabled and it still works fine. Keep in mind you should only ever mutate the handler's properties from the main thread. |
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.
-
Bug Description, Steps to Reproduce, Crash Logs, Screenshots, etc.
This is my app code:
This is my handler:
Then in my
AppDelegateI want to open the menu programmatically after 15 seconds like so:However, nothing happens. I can use the
statusItemtoperformClickbut I thought the binding would work. What am I missing?Also, there are parts in my app that would need to open the menu programmatically, but that would make this boolean stay true even if the user doesn't dismiss the view. Wouldn't that be an issue? Is there a way to "trigger" the opening once?
Beta Was this translation helpful? Give feedback.
All reactions