caiyue1993/IceCream

SwiftUI Example (I'm working on it)

bofrese opened this issue · 2 comments

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:

  • Few dependencies. Ideally only Realm and IceCream - to keep it simple.
  • A useful simple playground to use as base for experimentation, stress testing, hunting down bugs, error handling etc. rather than using your complex real life app for that.
  • A more 'complete' example, that allows you to see how it all works together. Possibly to serve as a 'blueprint' on a SwiftUI + Realm + IceCream app (The SwiftUI example from Realm uses Lists, which is not supported by IceCream, and Results are not an ObservableObject. Besides the SwiftUI.List / ForEach need to operate on a frozen Realm results to not crash when changing the model. etc., etc.....)

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

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.

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).