SwiftUI · Building a Social Media Feed: Part 2 | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4001741-swiftui/lessons/31

Hi Isaac.

I noticed that when you change the reaction while in toggle mode (eg say it was in .love but then changed to .funny) it doesnt automatically update the state of the mewsListView and filter it out. If I wanted to make that change what would you need to alter?

1 Like

That’s a good question! In this video we wanted to show the pieces working together so that concepts could be consolidated rather than focussing on architecture. In this case you’d need to change the way we’re doing it to pass bindings all the way in to the toggle in order to trigger a re-render. In our case we’re using a boolean isFilteringLovedPosts to trigger it, almost like an onChange event, but you’d need something that triggered that each time and it would be more complex than our example. Its a great exercise though! Laurie.

I have a question. In a MewsDetailView, you declared @ObeservedObject var post : MewsPost. Then you create a MewsSocialView. My question is why we dont pass binding “post” to MewsScocialView but creating @ObserverdObject post : MewsPost in MewsScocialView.

1 Like

There are different ways you can do it. Have you tried doing the above to see if it works? :smiley: Its good practice to have the binding and pass that in ideally. I’m not sure if it always behaves though when updating state! Laurie.