NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

Bidirectional BInding

Forums > SwiftUI


I've got @Published variable which has got a as a value, an array of my Model struct. This array is returned by a web API which implements a retrive API and delete item API.

Binding the array into an @ObservedObeject property in the view's List is quite easy: but how could I manage the deletion of a List element (performed by onDelete method) calling the delete item API ?

I guess it wouldn't be correct to perform an API deletion call directly in the onDelete method, because I'm th View.

I'd like to find an elegant method to trigger API deletion from the ViewModel class, where's defined the @Published variable: but how to manage that ?

I'm sorry if I'm not able to provide an example, It would be even fine for me to discuss about it from an abstract point of view.



Hacking with Swift is sponsored by Essential Developer

SPONSORED From January 26th to 31st you can join a FREE crash course for iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a senior developer!

Save your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.