I am trying to perform updates to a realm object in a SwiftUI application but get an error when performing the update.
What special magic is required to be able to perform and update to a realm object in response to a Gesture. In the example below from here (https://docs.mongodb.com/realm/sdk/ios/integrations/swiftui/) the Toggle() is bound directly to the items property.
I need to be able to call a method to perform multiple updates in response to a gesture - the example below does not show any examples of how to perform a custom update on an observed object. Is there an example that shows how you are supposed to do that with SwiftUI ?
Would it be possible to include a simple example of doing that in the example below - just for completeness.
Thanks
/// Represents a screen where you can edit the item's name.
struct ItemDetailsView: View {
@ObservedRealmObject var item: Item
var body: some View {
VStack(alignment: .leading) {
Text("Enter a new name:")
// Accept a new name
TextField("New name", text: $item.name)
.navigationBarTitle(item.name)
.navigationBarItems(trailing: Toggle(isOn: $item.isFavorite) {
Image(systemName: item.isFavorite ? "heart.fill" : "heart")
})
}.padding()
}
}