-
Notifications
You must be signed in to change notification settings - Fork 0
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
Widget changes not syncing to main app #1
Comments
Hi. Do you fetch your data when the app is in the foreground like monitoring the ScenePhase and fetch data when its value changes to .foreground? I haven’t encountered this issue before in iOS 17 Beta 6. |
I'm not doing anything special in the app besides the @query command in the view to pull from the ModelContainer. When I used your app, I had the same behavior though. Where when I completed a task, the main app didnt reflect the changes when brought into the foreground unless I killed and reopened the entire app |
Oh I reproduce this issue and seems that fetching and saving data manually won't work. However today Apple released the new Beta 8, I haven't have time to try it yet because I am on my trip, can you share the result after upgrading Xcode 15 beta and try? |
Beta 8 produces the same result, unfortunately. Sent from my iPhoneOn Aug 31, 2023, at 6:46 AM, JuniperPhoton ***@***.***> wrote:
Oh I reproduce this issue and seems that fetching and saving data manually won't work. However today Apple released the new Beta 8, I haven't have time to try it yet because I am on my trip, can you share the result after upgrading Xcode 15 beta and try?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
I think we should fire a feedback to Apple. I also tried changing the value in |
Good idea. I've never filed feedback with them before. Is that something you'd like to do? I'd be happy to figure it out otherwise |
I would. But I find out that the last feedbacks I submitted are still in the “open” state. But it’s still better to file a feedback though. By the way, did you test on real device or just use the simulator like me? |
Okay I’ll file it. I’ve tried on a simulator and physical device with the same results. Sent from my iPhoneOn Aug 31, 2023, at 8:14 PM, JuniperPhoton ***@***.***> wrote:
I would. But I find out that the last feedbacks I submitted are still in the “open” state. But it’s still better to fire a feedback though.
By the way, did you test on real device or just use the simulator like me?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
I have tested on a simulator and physical device with the same result. Feedback filed.. FB13107596 |
Thanks. I will also report this issue later. |
I have tried a method to avoid this issue. When fetching data: use a dedicated let context = ModelContext(sharedModelContainer)
let items = (try? context.fetch(FetchDescriptor<Item>())) ?? []
self.items = items And it's ok to update the data in an arbitrary context in Widget extension. The reason I tried this method is that my app MyerList has adopted this interactive widget feature before I make this demo and article and it works as expected. Though it uses Core Data instead of SwiftData, but I always uses the background context to update data and update data using a subscription-notification style. After all, I think it's still the issue of SwiftData (even in Beta 8). And I will still keep my eye on this issue. |
In my own app this has also been driving me bananas. Searched on GitHub for what others are doing and found this repo. On release version of Xcode 15, the issue remains unfortunately :( (posting for others who are googling, because there's not much out there). See video: CleanShot.2023-09-20.at.07.50.14-converted.mp4 |
There is a workaround posted before(see my previous comment). It's fine by me for now because I won't use SwiftData for production because supporting only iOS 17 will have very few users. |
Indeed that workaround works - thanks for fast reply. It's a shame to abandon Unfortunately, fetching Models from a background context means they can't be used in the UI :(
I don't think this can be changed - that might actually be a workaround if it could. A shame.
Correct, it doesn't seem to matter which context you use in the Widget. Also saving (or not) doesn't make a difference. |
Actually you can use modelContext modifier to set the context to be used in But the key of this workaround is to create a |
Thanks so much, was banging my head on that throughout the betas & was amazed it released with that bug. Now I can progress! 🙌 |
This workaround got my app working as well. Thanks @JuniperPhoton |
Can I get a code sample on how to use this workaround? I put and the following in
but it seems to have multiple thanks :) |
Thanks for the idea of a seperate context, that works for me when fetching data, but how would i then prevent another cloudkit instance from beeing created if i use cloudkkit? |
I did something nasty but it seems to work fine :)
Setting the same title won't change a thing but it will force SwiftData to pull the changes and apply them. That being said I've only a bunch of items at any given time, not sure how it's gonna work with hundreds or more but at least it should help those who have only a few at a given screen |
@ramzesenok your solution worked for me! I'm considering SwiftData to manage app state that is shared with AUv3 app extension. In my demo using 2 apps that share the same app group, I was only seeing additions and deletions, but not property changes. The |
Hello! Thanks for this demo project. I've noticed that when you modify a task through the widget, the change is not reflected in the main app until the app is restarted. I've seen the same behavior in my own apps using Interactive Widgets with SwiftData. Is this just expected behavior for the SwiftData beta currently?
The text was updated successfully, but these errors were encountered: