Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

'Missing argument parameter 'hideNew' in call'

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading