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)

How is GameViewModel defined ?

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

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

Accepted Answer

fixed

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.

many Errors in Xcode
 
 
Q