Extra arguments at positions #11, #12 in call SwiftUI [duplicate]

浪尽此生 提交于 2021-02-04 18:53:46

问题


I keep on getting an "Extra arguments at positions #11, #12 in call" error on my toggle switch in SwiftUI. I've seen other people have the "Extra Arguments in call" error, but the answers didn't seem to help; plus, my error says "positions #11, 12", which I haven't seen happen for others. I am using the Xcode 12 beta if that makes a difference.

import SwiftUI

let defaults = UserDefaults.standard

let notifsEnabled = defaults.bool(forKey: "NotifsEnabled")




struct Settings: View {
    @State var class11: String = defaults.string(forKey: "class11") ?? ""
    @State var class12: String = defaults.string(forKey: "class12") ?? ""
    @State var class13: String = defaults.string(forKey: "class13") ?? ""
    @State var class14: String = defaults.string(forKey: "class14") ?? ""
    
    @State var class21: String = defaults.string(forKey: "class21") ?? ""
    @State var class22: String = defaults.string(forKey: "class22") ?? ""
    @State var class23: String = defaults.string(forKey: "class23") ?? ""
    @State var class24: String = defaults.string(forKey: "class24") ?? ""
    
    @State var scheduleNotifications = notifsEnabled
    
    
    
    var body: some View {
        
        VStack(alignment: .leading) {
            
            Toggle(isOn: $scheduleNotifications) { //Extra arguments at positions #11, #12 in call
                Text("Daily schedule notifications")
            }
            
            if scheduleNotifications {
                Text(CreateNotifs())
            } else {
                Text(DeleteNotifs())
            }
            
            
            
            Text("This App will send you a reminder each day at 8:25 with the schedule for that day")
                .font(.caption)
                .foregroundColor(Color.gray)
            
            
            Divider()
            
            TextField("Class 1-1", text: $class11)
            
            TextField("Class 1-2", text: $class12)
            
            TextField("Class 1-3", text: $class13)
            
            TextField("Class 1-4", text: $class14)
            
            TextField("Class 2-1", text: $class21)
            
            TextField("Class 2-2", text: $class22)
            
            TextField("Class 2-3", text: $class23)
            
            TextField("Class 2-4", text: $class24)
            
            
            
            //Spacer()
        }
        .padding()
        .navigationBarTitle("Settings")
        
    }
    
}







回答1:


ViewBuilder supports only no more than 10 static views in one container... that's a reason of your error

Just group them

Group {

    TextField("Class 1-1", text: $class11)
    
    TextField("Class 1-2", text: $class12)
    
    TextField("Class 1-3", text: $class13)
    
    TextField("Class 1-4", text: $class14)
    
    TextField("Class 2-1", text: $class21)
    
    TextField("Class 2-2", text: $class22)
    
    TextField("Class 2-3", text: $class23)
    
    TextField("Class 2-4", text: $class24)

}


来源:https://stackoverflow.com/questions/62820488/extra-arguments-at-positions-11-12-in-call-swiftui

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!