0

In my code I get this error and I cannot figure out how to resolve it. The error is in the Trailing block of code

struct Map: View { @ObservedObject public var dataManager = DataManager.shared @Binding public var seqId: String // rz- to pass seqId to second view // @State public var seqId2: String = "" var body: some View { ZStack { VStack { Text("Results").foregroundColor(Color.white).onAppear{self.dataManager.downloadSeqData(seqId: self.seqId)} .onAppear(perform: playSound)/*rz want to add this sound func to contentview somehow, otherwise it will constantly play sound when page loads */ .edgesIgnoringSafeArea(.all) //rz- if strand is linear draw line if dataManager.dataSet?.INSDSeq.topology == "linear" { Rectangle() .fill(Color.black) .frame(width: 500, height: 20) } //rz- if strand is circular draw o if dataManager.dataSet?.INSDSeq.topology == "circular" { Circle() .stroke(Color.black, style: StrokeStyle(lineWidth: 20, lineCap: .round, lineJoin: .round)) .frame(width: 500, height: 500) } if dataManager.dataSet?.INSDSeq.topology != "circular" && dataManager.dataSet?.INSDSeq.topology != "linear"{ Text("Data Unavailable, try a new accession number.") } } .navigationBarItems( //rz - added home and genbank view to navigation bars leading: NavigationLink(destination: ContentView()) { Text("New Query") .font(.title) .foregroundColor(Color.black) }, trailing: NavigationLink(destination: Screen(seqId: self.$seqId)) { Text("GenBank View") .font(.title) .foregroundColor(Color.black) 

Error is in $seqId

NavigationLink(destination: Screen(seqId: self.$seqId)) { 

Here is the Screen view

import SwiftUI struct Screen: View { @ObservedObject public var dataManager = DataManager.shared @State private var seqId: String = "" var body: some View { VStack { TextField("Enter Accession Number", text: $seqId) .padding() Button("Search") { dataManager.downloadSeqData(seqId: seqId) } ScrollView { VStack(alignment: .leading) { Text(dataManager.dataSet?.INSDSeq.locus ?? "") .padding() Text(dataManager.dataSet?.INSDSeq.organism ?? "").padding() Text(dataManager.dataSet?.INSDSeq.source ?? "").padding() Text(dataManager.dataSet?.INSDSeq.taxonomy ?? "").padding() Text(dataManager.dataSet?.INSDSeq.topology ?? "").padding() Text(dataManager.dataSet?.INSDSeq.length == nil ? "" : "\(dataManager.dataSet!.INSDSeq.length)") .padding() Text(dataManager.dataSet?.INSDSeq.strandedness ?? "").padding() Text(dataManager.dataSet?.INSDSeq.moltype ?? "").padding() Text(dataManager.dataSet?.INSDSeq.sequence ?? "").padding() } .cornerRadius(10) VStack(alignment: .leading, spacing: 10) { ForEach(dataManager.featureList, id:\.self) { feature in VStack (alignment: .leading){ VStack (alignment: .leading) { Text(feature.INSDFeature_key).bold() Text(feature.INSDFeature_location) }.padding() IntervalSection(feature: feature) QualsSection(feature: feature) } .cornerRadius(10) } } .cornerRadius(20) } .padding(.horizontal) } } } struct IntervalSection: View { var feature: INSDFeature var body: some View { VStack (alignment: .leading){ ForEach(0..<feature.INSDFeature_intervals.count, id: \.self) { i in ForEach(0..<feature.INSDFeature_intervals[i].INSDInterval.count, id: \.self) { j in if let from = feature.INSDFeature_intervals[i].INSDInterval[j].INSDInterval_from { VStack (alignment: .leading){ Text("\(from)").bold() Text("\(feature.INSDFeature_intervals[i].INSDInterval[j].INSDInterval_to ?? -1)") } .padding() .cornerRadius(10) } } } } } } struct QualsSection: View{ var feature: INSDFeature var body: some View { VStack (alignment: .leading){ ForEach(0..<feature.INSDFeature_quals.count , id: \.self) { i in ForEach(0..<feature.INSDFeature_quals[i].INSDQualifier.count , id: \.self) { j in VStack (alignment: .leading){ Text(feature.INSDFeature_quals[i].INSDQualifier[j].INSDQualifier_name).bold() Text(feature.INSDFeature_quals[i].INSDQualifier[j].INSDQualifier_value) } .padding() .cornerRadius(10) } } } } 

}

5
  • And what is Screen? What does the init method look like for Screen? Most likely you don't have such an init. Commented Oct 30, 2020 at 14:48
  • Screen is the content view that displays the information in a list format. There is no init method in the screen page Commented Oct 30, 2020 at 14:53
  • Too much trouble to post the code? What properties does it have, there is always an synthesised init if it is a struct which I assume it is. Commented Oct 30, 2020 at 14:59
  • just uploaded it Commented Oct 30, 2020 at 15:04
  • And the view doesn't take a seqId as parameter since that property is private (and is a @State variable). It looks to me that the Screen view doesn't need to be initialised with seqId as it takes it as input? Otherwise you need to change it to @Binding and remove private Commented Oct 30, 2020 at 15:14

1 Answer 1

1

In SwiftUI you should use Binding instead of State in cases, where the data is coming from another view. Furthermore both attributes of Screen are private, therefore they can't be accessed in this case set from outside of the struct itself.

I would suggest to make seqID in Screen public like you did it with dataManager and change it to State

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.