UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Bidirectional BInding

Forums > SwiftUI

Hello.

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.

Thanks.

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.