Tim J McGrath
Tim J McGrath

Reputation: 5

Getting the error Extra Argument in Call SwiftUi

I am getting a error extra argument in call, I have more than 11 views in my VStack I have tried to Group { } some elements but it is not working.

I have tried to put them in an array but couldn't work out how to make the time part work once the tables are in an array

I am sure I am just not grouping them correctly

Any help would be great

import SwiftUI

struct TimeListView: View {
    
    @State var table1 = false
  
    
    @State var timeForShow1: String?
 
    
    
    var body: some View {
        
        
        VStack {
            
            Text("Booking End Times")
                .font(.title)
                .fontWeight(.bold)
            
            List {
                
                HStack {
                    
                    Text("Table 1 -")
                        .onTapGesture {
                            timeForShow1 = getCurrentTime
                            table1.toggle()
                        }
                    
                    
                    if table1 { Text(timeForShow1 ?? "not available!") }
                    
                }
                
                
                HStack {
                    
                    Text("Table 2 -")
                        .onTapGesture {
                            timeForShow2 = getCurrentTime
                            table2.toggle()
                        }
                    
                    
                    if table2 { Text(timeForShow2 ?? "not available!") }
                    
                }
                
                
                
                HStack {
                    
                    Text("Table 3 -")
                        .onTapGesture {
                            timeForShow3 = getCurrentTime
                            table3.toggle()
                        }
                    
                    
                    if table3 { Text(timeForShow3 ?? "not available!") }
                    
                }
                
                HStack {
                    
                    Text("Table 4 -")
                        .onTapGesture {
                            timeForShow4 = getCurrentTime
                            table4.toggle()
                        }
                    
                    
                    if table4 { Text(timeForShow4 ?? "not available!") }
                    
                }
                
                HStack {
                    
                    Text("Table 5 -")
                        .onTapGesture {
                            timeForShow5 = getCurrentTime
                            table5.toggle()
                        }
                    
                    
                    if table5 { Text(timeForShow5 ?? "not available!") }
                    
                }
                
                HStack {
                    
                    Text("Table 6 -")
                        .onTapGesture {
                            timeForShow6 = getCurrentTime
                            table6.toggle()
                        }
                    
                    
                    if table6 { Text(timeForShow6 ?? "not available!") }
                    
                }
                HStack {
                    
                    Text("Table 7-")
                        .onTapGesture {
                            timeForShow7 = getCurrentTime
                            table7.toggle()
                        }
                    
                    
                    if table7 { Text(timeForShow7 ?? "not available!") }
                    
                }
                HStack {
                    
                    Text("Table 8 -")
                        .onTapGesture {
                            timeForShow8 = getCurrentTime
                            table8.toggle()
                        }
                    
                    
                    if table8 { Text(timeForShow8 ?? "not available!") }
                    
                }
                
                HStack {
                    
                    Text("Table 9 -")
                        .onTapGesture {
                            timeForShow9 = getCurrentTime
                            table9.toggle()
                        }
                    
                    
                    if table9 { Text(timeForShow9 ?? "not available!") }
                    
                }
                
                HStack {
                    
                    Text("Table 10 -")
                        .onTapGesture {
                            timeForShow10 = getCurrentTime
                            table10.toggle()
                        }
                    
                    
                    if table10 { Text(timeForShow10 ?? "not available!") }
                    
                }
                // error when adding 11th table
                HStack {
                    
                    Text("Table 11 -")
                        .onTapGesture {
                            timeForShow11 = getCurrentTime
                            table11.toggle()
                        }
                    
                    
                    if table11 { Text(timeForShow11 ?? "not available!") }
                    
                }
                
                
                
            }
            
        }
        
        
        
        
    }
    
    
}

Upvotes: 0

Views: 785

Answers (1)

swiftPunk
swiftPunk

Reputation: 1

You have to use Group in more than 10 item in body! as you can see in my code, also inside a Group you can have just 10 item!

var body: some View {
    
    
    VStack {
        
        Text("Booking End Times")
            .font(.title)
            .fontWeight(.bold)
        
        List {
            
            Group {                         // <<: Here
                
                
                HStack {
                    
                    Text("Table 1 -")
                        .onTapGesture {
                            timeForShow1 = getCurrentTime
                            table1.toggle()
                        }
                    
                    
                    if table1 { Text(timeForShow1 ?? "not available!") }
                    
                }
                
                HStack {
                    
                    Text("Table 2 -")
                        .onTapGesture {
                            timeForShow2 = getCurrentTime
                            table2.toggle()
                        }
                    
                    
                    if table2 { Text(timeForShow2 ?? "not available!") }
                    
                }
                
                HStack {
                    
                    Text("Table 3 -")
                        .onTapGesture {
                            timeForShow3 = getCurrentTime
                            table3.toggle()
                        }
                    
                    
                    if table3 { Text(timeForShow3 ?? "not available!") }
                    
                }
                
                HStack {
                    
                    Text("Table 4 -")
                        .onTapGesture {
                            timeForShow4 = getCurrentTime
                            table4.toggle()
                        }
                    
                    
                    if table4 { Text(timeForShow4 ?? "not available!") }
                    
                }
                
                HStack {
                    
                    Text("Table 5 -")
                        .onTapGesture {
                            timeForShow5 = getCurrentTime
                            table5.toggle()
                        }
                    
                    
                    if table5 { Text(timeForShow5 ?? "not available!") }
                    
                }
                
                
            }
            
            
            Group {                         // <<: Here
                
                HStack {
                    
                    Text("Table 6 -")
                        .onTapGesture {
                            timeForShow6 = getCurrentTime
                            table6.toggle()
                        }
                    
                    
                    if table6 { Text(timeForShow6 ?? "not available!") }
                    
                }
                
                HStack {
                    
                    Text("Table 7-")
                        .onTapGesture {
                            timeForShow7 = getCurrentTime
                            table7.toggle()
                        }
                    
                    
                    if table7 { Text(timeForShow7 ?? "not available!") }
                    
                }
                
                HStack {
                    
                    Text("Table 8 -")
                        .onTapGesture {
                            timeForShow8 = getCurrentTime
                            table8.toggle()
                        }
                    
                    
                    if table8 { Text(timeForShow8 ?? "not available!") }
                    
                }
                
                HStack {
                    
                    Text("Table 9 -")
                        .onTapGesture {
                            timeForShow9 = getCurrentTime
                            table9.toggle()
                        }
                    
                    
                    if table9 { Text(timeForShow9 ?? "not available!") }
                    
                }
                
                HStack {
                    
                    Text("Table 10 -")
                        .onTapGesture {
                            timeForShow10 = getCurrentTime
                            table10.toggle()
                        }
                    
                    
                    if table10 { Text(timeForShow10 ?? "not available!") }
                    
                }
                
                
                HStack {
                    
                    Text("Table 11 -")
                        .onTapGesture {
                            timeForShow11 = getCurrentTime
                            table11.toggle()
                        }
                    
                    
                    if table11 { Text(timeForShow11 ?? "not available!") }
                    
                }
                
            }
            
            
            
            
            
        }
        
    }
    
    
    
    
}

Upvotes: 1

Related Questions