caiyue1993 / IceCream

Sync Realm Database with CloudKit
MIT License
1.94k stars 245 forks source link

SwiftUI Example (I'm working on it) #207

Open bofrese opened 4 years ago

bofrese commented 4 years ago

I needed a more complete example on how SwiftUI + Realm + IceCream all works together, and a simple app to experiment on, rather than my "real'' app. I file this issues, mostly to let you know that I'm already working on it, and making good progress. I'll push it to my github fork soon, so you can have a preview, and make a pull request when I think it's ready.

Design goals:

I'll do this anyway, but do you want this added as another example to the IceCream repo? Any other requests, needs, etc.?

Regards, Bo

bofrese commented 4 years ago

I have created a first version of the SwitUI example. You can see it at https://github.com/bofrese/IceCream/tree/swiftui_example/SwiftUIExample and I have also created a pull request for this.

The Example app includes some 'stress testing' tools, to quickly add 10 or 100 people+cats to realm. My experience so far is that is is to easy to get errors in the IceCream/CloudKit layer, which the app never recovers from, leaving the data out of sync between devices. This especially happens when inserting many records at a time. Some records are simply never synchronised. I have yet to discover a way to catch these errors, and to find a way to recover from them. I have studied the existing example app, and can not see that it should be anything in my Example app, so currently I suspect bugs in IceCream. However, it is my impression that a lot of people are using IceCream for production apps(?), and I can not believe they would be doing that, if it was this easy to get data out of sync. So I'm probably overlooking something......??

So if anybody would like to try out the new SwiftUIExample App, stress test it a bit, and review the code, I would much appreciated it.

riverbaymark commented 3 years ago

Hi @bofrese and thanks for all your work on this. I'm new to IceCream so still learning, but love what it brings. I think I may know what the deal is with the data falling out of sync. I cannot tell you how many hours I have chased data that depends on @ObservableObject. Things fall out of scope all the time. I'm going to try your solution and replace @ObservableObject with @StateObject where applicable. This is iOS14 only but keeps things in sync (like ObservableObject was supposed to but fails to do).