Reputation: 197
Error : Argument passed to call that takes no arguments
Explanation : I have 2 different views, ContentView
and MainView
. There is a @Binding
variable in MainView
which is @Binding var showMenu: Bool
. When I try to call MainView
with the an argument, I get the error specified above.
Code Snippets :
struct ContentView: View {
@State var showMenu = false
var body: some View {
GeometryReader { geometry in
MainView(showMenu: $showMenu)
.frame(width: geometry.size.width, height: geometry.size.height)
.offset(x: self.showMenu ? geometry.size.width/2 : 0)
.disabled(self.showMenu ? true : false)
}
}
}
and
struct MainView: View {
@Binding var showMenu: Bool
//unrelated variable declarations
init() {
//unrelated code
}
var body: some View {
//unrelated code
}
Upvotes: 1
Views: 3066
Reputation: 534885
The problem is this line:
init() {
//unrelated code
}
When you said that, you said that the only to make a MainView is by saying MainView()
. So it is indeed true that you now can't say MainView(showMenu:...)
.
You have three main choices that I can see:
Delete the whole init()
.
Replace the whole init()
with something like this:
init(showMenu: Binding<Bool>) {
self._showMenu = showMenu
// other stuff?
}
Rethink the architecture. (We'd need to see more of what this binding is for.)
Upvotes: 4