Home > Enterprise >  Swift UI Error message when trying to add text
Swift UI Error message when trying to add text

Time:09-21

I'm having an issue where if I try to add any other pieces of text, buttons, or anything view related it gives the error of Extra argument in call. I haven't found a solution to this or whats causing it, though I think it might be that theres to many text boxes and buttons but as stated before I'm not fully sure. Sorry for the long code I'm not sure what is causing the error so I thought it would be the most helpful to include it all

struct DicePage: View {
    @State public var DiceRoll: Int = 0
    @State public var Modifier: String = ""
    @State public var Total: Int = 0
    @State public var showingAlert = false
    @State public var LastDie: String = "D20"
    @State public var NumRolledDie: String = ""
    @State public var RolledNumbers: [Int] = []
    @State public var RolledNumbersString: [String] = []
    @State public var Placeholder: Int = 0
    @State private var CustomDie: String = ""
    @State public var Storage: GloabalStorage = GloabalStorage()
    
    var body: some View {
        VStack {
            ScrollView {
                Text("The Current Value Rolled is: \(RolledNumbersString.joined(separator: ", ")), with a Modifier of \(String(convert(Modifier, true))) rolling \(String(convert(NumRolledDie, false))) die, to get a total of \(String(Total)), \nYou also rolled a \(LastDie).")
                
                // Text Inputs ------------------------------------------------------------------------------
                TextField("Enter Modifier...", text: $Modifier)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                
                TextField("How Many Die Rolled...\nMake sure this is greater then 1", text: $NumRolledDie)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                
                TextField("Enter Custom Die Value...", text: $CustomDie)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                // Text Inputs ------------------------------------------------------------------------------
                
                // Custom Die
                Button(action : {
                    RolledNumbers.removeAll()
                    RolledNumbersString.removeAll()
                    
                    // New Code for the thing yaknow
                    if (convert(NumRolledDie, false) > 80) { NumRolledDie = "80" }
                    for _ in 0...convert(NumRolledDie, false) - 1 {
                        Placeholder = Int.random(in: 1...convert(CustomDie, false))
                        RolledNumbers.append(Placeholder)
                        RolledNumbersString.append(String(Placeholder))
                    }
                    Total = RolledNumbers.Total(RolledNumbers)   convert(Modifier, true)
                    LastDie = "D\(String(convert(CustomDie, false)))"
                    Storage.effectNoise = true
                    
                }) {
                    Text("   ROLL THE DICE: D\(String(convert(CustomDie, false)))   ")
                        .background(
                            ZStack {
                                Color.purple
                                LinearGradient(gradient: Gradient(colors: [Color.white.opacity(0.3), Color.clear]), startPoint: .top, endPoint: .bottom)
                            })
                        .foregroundColor(.black)
                        .cornerRadius(21)
                        .padding()
                }
                
                // D100 Dice Roll
                Button(action : {
                    RolledNumbers.removeAll()
                    RolledNumbersString.removeAll()
                    
                    // New Code for the thing yaknow
                    if (convert(NumRolledDie, false) > 80) { NumRolledDie = "80" }
                    for _ in 0...convert(NumRolledDie, false) - 1 {
                        Placeholder = Int.random(in: 1...100)
                        RolledNumbers.append(Placeholder)
                        RolledNumbersString.append(String(Placeholder))
                    }
                    Total = RolledNumbers.Total(RolledNumbers)   convert(Modifier, true)
                    LastDie = "D100"
                }) {
                    Text("   ROLL THE DICE: D100   ")
                        .background(
                            ZStack {
                                Color.purple
                                LinearGradient(gradient: Gradient(colors: [Color.white.opacity(0.3), Color.clear]), startPoint: .top, endPoint: .bottom)
                            })
                        .foregroundColor(.black)
                        .cornerRadius(21)
                        .padding()
                }
                
                // D20 Dice Roll
                Button(action : {
                    RolledNumbers.removeAll()
                    RolledNumbersString.removeAll()
                    
                    // New Code for the thing yaknow
                    if (convert(NumRolledDie, false) > 80) { NumRolledDie = "80" }
                    for _ in 0...convert(NumRolledDie, false) - 1 {
                        Placeholder = Int.random(in: 1...20)
                        RolledNumbers.append(Placeholder)
                        RolledNumbersString.append(String(Placeholder))
                    }
                    Total = RolledNumbers.Total(RolledNumbers)   convert(Modifier, true)
                    LastDie = "D20"
                }) {
                    Text("   ROLL THE DICE: D20   ")
                        .background(
                            ZStack {
                                Color.purple
                                LinearGradient(gradient: Gradient(colors: [Color.white.opacity(0.3), Color.clear]), startPoint: .top, endPoint: .bottom)
                            })
                        .foregroundColor(.black)
                        .cornerRadius(21)
                        .padding()
                }
                
                
                // D12 Dice Roll
                Button(action : {
                    RolledNumbers.removeAll()
                    RolledNumbersString.removeAll()
                    
                    // New Code for the thing yaknow
                    if (convert(NumRolledDie, false) > 80) { NumRolledDie = "80" }
                    for _ in 0...convert(NumRolledDie, false) - 1 {
                        Placeholder = Int.random(in: 1...12)
                        RolledNumbers.append(Placeholder)
                        RolledNumbersString.append(String(Placeholder))
                    }
                    Total = RolledNumbers.Total(RolledNumbers)   convert(Modifier, true)
                    LastDie = "D12"
                }) {
                    Text("   ROLL THE DICE: D12   ")
                        .background(
                            ZStack {
                                Color.purple
                                LinearGradient(gradient: Gradient(colors: [Color.white.opacity(0.3), Color.clear]), startPoint: .top, endPoint: .bottom)
                            })
                        .foregroundColor(.black)
                        .cornerRadius(21)
                        .padding()
                }
                
                
                
                // D 10 Dice Roll
                Button(action : {
                    RolledNumbers.removeAll()
                    RolledNumbersString.removeAll()
                    
                    // New Code for the thing yaknow
                    if (convert(NumRolledDie, false) > 80) { NumRolledDie = "80" }
                    for _ in 0...convert(NumRolledDie, false) - 1 {
                        Placeholder = Int.random(in: 1...10)
                        RolledNumbers.append(Placeholder)
                        RolledNumbersString.append(String(Placeholder))
                    }
                    Total = RolledNumbers.Total(RolledNumbers)   convert(Modifier, true)
                    LastDie = "D10"
                }) {
                    Text("   ROLL THE DICE: D10   ")
                        .background(
                            ZStack {
                                Color.purple
                                LinearGradient(gradient: Gradient(colors: [Color.white.opacity(0.3), Color.clear]), startPoint: .top, endPoint: .bottom)
                            })
                        .foregroundColor(.black)
                        .cornerRadius(21)
                        .padding()
                }
                
                
                // D8 Dice Roll
                Button(action : {
                    RolledNumbers.removeAll()
                    RolledNumbersString.removeAll()
                    
                    // New Code for the thing yaknow
                    if (convert(NumRolledDie, false) > 80) { NumRolledDie = "80" }
                    for _ in 0...convert(NumRolledDie, false) - 1 {
                        Placeholder = Int.random(in: 1...8)
                        RolledNumbers.append(Placeholder)
                        RolledNumbersString.append(String(Placeholder))
                    }
                    Total = RolledNumbers.Total(RolledNumbers)   convert(Modifier, true)
                    LastDie = "D8"
                }) {
                    Text("   ROLL THE DICE: D8   ")
                        .background(
                            ZStack {
                                Color.purple
                                LinearGradient(gradient: Gradient(colors: [Color.white.opacity(0.3), Color.clear]), startPoint: .top, endPoint: .bottom)
                            })
                        .foregroundColor(.black)
                        .cornerRadius(21)
                        .padding()
                }
            }
        }
    }
}

CodePudding user response:

SwiftUI only allows 10 View components at a time. To get around this you would either have to use the Group struct and wrap some of your view components. OR make separate view files that have common view designs.

Documentation for Group: https://developer.apple.com/documentation/swiftui/group

  • Related