many Errors in Xcode

[QuestionView(question:viewModel.currentQuestion)

Errors

Cannot convert value of type 'Binding' to expected argument type 'Question'

Referencing subscript 'subscript(dynamicMember:)' requires wrapper 'ObservedObject.Wrapper'

Value of type 'GameViewModel' has no dynamic member 'currentQuestion' using key path from root type 'GameViewModel'

Insert '$'

  • Could you show the complete code, not just a line ? Is it SwiftUI (the tag doesn't say so)

Add a Comment

Accepted Reply

fixed

  • Can you share the solution? (And possibly, mark it as SOLVED?)

Add a Comment

Replies

How is GameViewModel defined ?

Is currentQuestion a plain var (then it should work) or a State var ?

  • I believe it is state var I posted full code below

Add a Comment

Updated Question




struct GameView: View {

    var viewModel = GameViewModel()

    

    var body: some View {

        ZStack {

            GameColor.main.ignoresSafeArea()

            VStack {

                Text(viewModel.questionProgressText)

                    .font(.callout)

                    .multilineTextAlignment(.leading)

                    .padding()

                QuestionView(question: viewModel.currentQuestion) --> error here

            }

            .foregroundColor(.white)

            .navigationBarHidden(true)

            .environmentObject(viewModel)

        }

    }

}





struct ContentView_Previews: PreviewProvider {

    static var previews: some View {

        GameView()

    }

}

Error

Value of type 'GameViewModel' has no member 'currentQuestion'

I can't edit My initial Question

  • It Is SwiftUI

  • How is GameViewModel defined ?

Add a Comment

fixed

  • Can you share the solution? (And possibly, mark it as SOLVED?)

Add a Comment

I had the same problem on my universal SwiftUI app. problem was one of the files I made (the one I defined my struct in), didn't have the macOS target selected.