Hi @James_Cicenia , what do you mean you want to cancel.
Do you want to use @ObservedRealmObject as a draft object and only add it to the database when you want to, or maybe you want to revert any changes to the object on the database “canceling” all the previous write to that object?
Unfortunately you cannot use @ObservedRealmObject as a draft object, you can instead use @StateRealmObject as an unmanaged object and then persist it into the database when is ready.
If iDataModel.company is managed by the Realm (which based on your code, it is)– then assigning it to companyInfoPreferenceVM.company means that companyInfoPreferenceVM.company is now the same reference to the company that you had read from the Realm. So when you bind the name of that company to the textField, it’s going to write directly to the Realm that the company came from.
What you would want here would be the reverse of what you are doing– instead of assigning iDataModel.company to the companyInfoPreferenceVM.company, once you are ready to “save” the “draft data”, you can either:
assign the fields you so choose to the iDataModel.company object in a write transaction, or
add the draft company to the Realm as an update for the same primary key
What is the proper way to create a draft company that is not realm persisted? Is there some helper method or I have to create a method? Thanks, but still don’t understand why it would sync to the database vs. just locally until transacted.
self.company = Company(value: company) had the same issue.
I would prefer not to have vars linked to textfield.