This seems like a simple question, but now I've been going in circles for an embarrassingly long time so time to ask. What is the best method for detecting a change in ANY property of a reference object? I am using Backendless as the backend so I'm committed to using classes at this point so going with structs aren't an option.
Here are two approaches I've been trying...
Use some combination of .objectWillChange and/or .sink, but I can only get those to work on individual properties of an object. If I attach to the object it only notifies when I assign a new obj to the var.
Creating a copy of the object as a reference to check against for changes requires that I create some version of a deep copy which seems like the wrong way to go and very hacky.
The point for this is that I don't want to "save" the object every time a single property changes. I'd rather wait and save the whole object on dismiss or something similar, but I can't find the best way to mark an object as "changed" without writing code for every single property...which seems weird when there are already Publishers, but I can't find a method that watches the object for ANY Published events to emit. Or maybe this just isn't the right approach at all?
Here is a specific use case:
- Class instance is passed into a view.
- Class instance MIGHT be changed in the view.
- On exiting the view I need to save the object IF it was changed.
Step 3 is where I’m stuck. I don’t know how to determine if the class instance has changed. I don’t want to run the Backendless save function unless I need to, but I haven’t found a way to determine if the object has changed without coding for every single property. If that’s just how it’s done in swift then it is what it is, but makes me think I’m missing something. Or am I wrong to approach the problem like this?