调用 SwiftUI 中位置 #11、#12 的额外参数 [英] Extra arguments at positions #11, #12 in call SwiftUI

查看:96
本文介绍了调用 SwiftUI 中位置 #11、#12 的额外参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到在调用中的位置 #11、#12 的额外参数";我在 SwiftUI 中的切换开关出错.我见过其他人有通话中的额外参数"错误,但答案似乎没有帮助;另外,我的错误是位置 #11, 12",我还没有看到其他人发生过这种情况.如果有什么不同,我将使用 Xcode 12 beta.

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")
        
    }
    
}






推荐答案

ViewBuilder 在一个容器中只支持不超过 10 个静态视图......这是你出错的原因

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

只需将它们分组

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)

}

这篇关于调用 SwiftUI 中位置 #11、#12 的额外参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆