I am trying to assign a value I fetch and parse from JSON to another view.
struct ContentView: View {
@State private var showAlert = false
@State private var showAbout = false
@State private var showModal = false
@State private var title = "hi"
@State private var isCodeSelectorPresented = false
@ObservedObject var fetch = FetchNovitads()
var body: some View {
VStack {
NavigationView {
List(fetch.Novitadss) { Novitads in
VStack(alignment: .leading) {
// 3.
Text(Novitads.name!.de)
.platformFont()
.fontWeight(.black)
Text(Novitads.textTeaser.de)
.platformFont()
.fontWeight(.medium)
.onTapGesture {
self.showModal.toggle()
// 3.
}.sheet(isPresented: self.$showModal) {
ModalView(showModal: self.$showModal,
title: self.$title)
}
In this sample code the title (defined as "hi") is passed correctly. What I want to do however is to assign the value of Novitads.name!.de to the title variable so that I can use it in the modal view.
self.$titleinModalView? Do you really need binding here? BTW, sheet in List will not work as you expect - you have to move it out of List.