midnightchip / RelocateMe

GNU General Public License v3.0
12 stars 1 forks source link

fixed ObservedObject usage #2

Closed Luki120 closed 2 years ago

Luki120 commented 2 years ago

Hey, so I was looking through the source here and noticed all views were using @ ObservedObject for the classes that conform to the ObservableObject protocol, however it seems @ StateObject would be the correct use here, since you are creating the objects directly in the views, so the view should know that it owns that object and should keep it alive, instead of recreating it everytime the view is discarded and redrawned, which is one of the main differences between both wrappers. Basically all the answers in this post explain it quite well, not just the accepted one. I also marked @ State variables as private to add encapsulation since they shouldn't be shared across views. Sadly I can't test the code since the project isn't open source to the point it's compilable, plus I think you're using modifiers that were added after iOS 14.5, so my sdk doesn't have them, and also I'm on Linux and this is an xcode app so rip. But anyways it should still compile and there shouldn't be any visible differences.

Luki120 commented 2 years ago

No intentions of either closing or merging.