您可以根据以下内容进行更新:
@State var array = [String](repeating: "", count: 3)
@State var array1 = [String](repeating: "", count: 1)
@State var array2 = [String](repeating: "", count: 3)
@State var var1 = true
@State var var2 = true
@State var var3 = true
var body: some View{
VStack {
HStack{ TextField("text0", text: $array[0])
TextField("text0", text: $array[1])
TextField("text0", text: $array[2])
}.onReceive(array.publisher) { _ in
self.var1 = self.array.allSatisfy{$0.isEmpty}
self.check()
}
HStack{
TextField("text1", text: $array1[0])
}.onReceive(array1.publisher) { _ in
self.var2 = self.array1.allSatisfy{$0.isEmpty}
self.check()
}
HStack{
TextField("text2", text: $array2[0])
TextField("text2", text: $array2[1])
TextField("text2", text: $array2[2])
}.onReceive(array2.publisher) { _ in
self.var3 = self.array2.allSatisfy{$0.isEmpty}
self.check()
}
}
}
func check(){
switch ( (var1 ? 1 : 0) | (var2 ? 2: 0) | (var3 ? 4:0)){
case 0b001: print( "var1", var1)
case 0b010: print( "var2", var2)
case 0b100: print( "var3", var3)
default: return
}
}
}