0

Im not sure if this is even possible. I have a view that takes in a string parameter. Then in that same view I was to initialize a @State variable to a set of data I will load which I want other views to be able to access. However, in order to load that data set I need the value of that passed in string parameter.

I'm getting the "Cannot use instance member 'chosenStoryNameIn' within property initializer; property initializers run before 'self' is available". Is there some wait to work around this?

struct shortStoryView: View {

  @State var chosenStoryNameIn: String

  @State var showPopUpScreen: Bool = false
  @State var showQuestionDropdown: Bool = false

  @State var data: shortStoryData = shortStoryData(chosenStoryName: chosenStoryNameIn)



  var body: some View {
      
HangarRash
  • 7,314
  • 5
  • 5
  • 32
mzm0227
  • 43
  • 5
  • I think I figured it out, the variable does need to be @State for my purposed. So I changed it to a regular var and created a computed variable – mzm0227 May 11 '23 at 18:12

0 Answers0