Home > Software design >  'Missing argument parameter 'hideNew' in call'
'Missing argument parameter 'hideNew' in call'

Time:07-01

I am trying to toggle a Bool variable so that I can unhide a view when an image acting as a button is clicked. I'm not sure what the issue is because as far as I can tell everything is right. Then again though, I am pretty new to Swift. Here's my code:

struct ContentView: View {
    @State private var hideNew: Bool = true
    var body: some View {
        ZStack {
            VStack {
                HeaderView() //Error shows here: 'Missing argument parameter 'hideNew' in call'
                    .padding(.bottom, -1.5)
                ScrollView {
                    CountdownView()
                }
                Spacer()
            }
            .frame(width: 600, height: 500)
            if hideNew == false {
                NewDateView()
            }
        }
    }
}

//  The view for the header section
struct HeaderView: View {
    var buttonSize: CGFloat = 25
    @Binding var hideNew: Bool
    var body: some View {
        Spacer()
            .frame(maxHeight: 10)
        HStack {
            Spacer()
            Text("Date Countdown")
                .font(.largeTitle)
                .padding(.trailing, -buttonSize)
            Spacer()
            Image(systemName: "plus")
                .padding(.trailing, 10)
                .frame(width: buttonSize, height: buttonSize)
                .onTapGesture {
                    hideNew.toggle() //This is what I assume the issue is, but I don't actually know what's wrong.
                }
        }
        Spacer()
            .frame(height: 10)
        ExtendedDivider()
            .frame(height: 1.5)
    }
}

Any help would be greatly appreciated. Cheers

CodePudding user response:

There are two mistakes in your code.

  1. You have to bind (pass) hideNew var to HeaderView
HeaderView(hideNew: $hideNew) //Error shows here: 'Missing argument parameter 'hideNew' in call'
  1. Your if condition is wrong. You are creating a new object of HeaderView which is meaningless.
// Other Code
if hideNew == false {
   NewDateView()
}
// Other Code
  • Related