SwiftUI - NavigationView Error message - Argument passed to call that takes no arguments

Viewed 7314

I am trying to implement a really basic NavigationView in SwiftUI. When I try the sample code that I have seen on other websites it generates an error message in Xcode. I am not sure why or how to fix this.

I have tried to clean the project, quit Xcode-Beta and restart it but that did not work.


struct ContentView : View {
    var body: some View {
        NavigationView {
            Text("This is a great app")
        }
    }
}

I thought the code above should work but the error I get says:

"Argument passed to call that takes no arguments."

Any ideas or suggestions?

6 Answers

VStack can only take 10 argument. If more, there will be error, so you should make it nested.

from

VStack{

}

to

VStack{
    VStack{
    }
    VStack{
    }  
}

I had this same error message too and figured out what I did wrong and then kind of felt like an idiot. Ha ha.

Take a look: Error

It took me a while to figure out that my struct was the same name as a previously defined struct VStack. Whoops!

So I'm wondering if you had a file in your project that did this too.

Testing Xcode 11.2.1 and it's still buggy. I noticed when I keep adding primitive views to my ContentView, I start getting errors like "Argument passed to call that takes no arguments", "Type of expression is ambiguous without more context" etc. on primitive views which worked before. When I replaced, for example,

ScrollView {
            VStack {
        Text
        Button
        Image
        Text
        Button
        Image
        Text
        Button
        Image
        ...
        }
    }

with

       ScrollView {
            VStack {
        VStack {
            Text
            Button
            Image
        }
        VStack {
            Text
            Button
            Image
        }
        VStack {
            Text
            Button
            Image
        }
        ...
        }

my code started to compile and run again.

check-in your app is there any Swifui class with the name NavigationView. also when you jump to the definition from NavigationView it should refer to:

  @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 7.0, *)
  public struct NavigationView<Content> : View where Content : View {

  public init(@ViewBuilder content: () -> Content)

/// The type of view representing the body of this view.
///
/// When you create a custom view, Swift infers this type from your
/// implementation of the required `body` property.
public typealias Body = Never
}

I found this problem when I accidentally try to redefine Text struct. Check if you naming your custom class the same as those in SwiftUI.

@Matteo Pacini helped me find the answer. When I started a new Xcode Project just to test the code above everything worked. I had a lot of files and was testing a lot of different code while experimenting with SwiftUI in my other project and for some reason XCode was always generating this error.

When I tried everything in a new project it worked. Something to be aware of while testing. Hope this helps others avoid similar problems.

Related