Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Extra argument in call" Spacer()

Tags:

swiftui

I am very new to swiftui, and am making a simple game for learning reasons. I have no idea why this error would show because I did basically the same thing a couple of lines up. If you want to check the code yourself just use some random images. I cant post this post because it has to much code. it is telling me that I have to add more text so that is what I am doing right now, you do not have to read this.

import SwiftUI
struct ContentView: View {
    var body: some View {
        ZStack{
            Image("background")
                .ignoresSafeArea()         
            VStack{
                Spacer()
                Image("logo")
                Spacer()
                HStack {
                    Spacer()
                    Image("card3")
                    Spacer()
                    Image("card4")
                    Spacer()
                        }
                Spacer()
                Image("dealbutton")
                Spacer()
                HStack{
                    Spacer()
                    Text("Player")
                    Spacer()
                    Text("CPU")
                    Spacer()
                }
                .font(/*@START_MENU_TOKEN@*/.title/*@END_MENU_TOKEN@*/)
                .foregroundColor(.white)
                Spacer()
                HStack{
                    Spacer()
                    Text("0")
                    Spacer()
                    Text("0")
                    Spacer()
                }
                Spacer() //here is the error             
            }
    }
    }
    }
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
like image 933
GrainsGames Avatar asked Sep 11 '25 07:09

GrainsGames


1 Answers

Note Spacer() is a view, and so you are exceeding the number of views (10) allowed inside another view. Try some variations of this, or use Group {...}:

struct ContentView: View {
    
    var cardView: some View {
        Group {
            Spacer()
            HStack {
                Spacer()
                Image("card3")
                Spacer()
                Image("card4")
                Spacer()
            }
            Spacer()
        }
    }
    
    var textview: some View {
        Group {
            Spacer()
            HStack{
                Spacer()
                Text("0")
                Spacer()
                Text("0")
                Spacer()
            }
            Spacer()
        }
    }
    
    var devView: some View {
        Group {
            Spacer()
            HStack{
                Spacer()
                Text("Player")
                Spacer()
                Text("CPU")
                Spacer()
            }
            Spacer()
        }
    }
    
    var body: some View {
        ZStack{
            Image("background")
                .ignoresSafeArea()
            VStack{
                Spacer()
                Image("logo")
                Spacer()
                cardView
                Image("dealbutton")
                devView
                    .font(.title)
                    .foregroundColor(.white)
                textview
                Spacer()
            }
        }
    }
}
like image 105
workingdog support Ukraine Avatar answered Sep 13 '25 21:09

workingdog support Ukraine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!