I am working in a Swift Playground and I am using multiple toggles to determine if an action in true or false. And from there, the specific combination of them will display a number assigned to each combination. Since I have 4 toggles, I decided to make 16 if else statements but it is really slowing down my playground. Is there a way to use less statements?
Toggle(isOn: $washingHandsToggle) {
Text("Washing Hands Regularly")
}.padding(40)
Toggle(isOn: $wearingMaskToggle) {
Text("Wearing a Protective Mask")
}.padding(40)
Toggle(isOn: $coverMouthToggle) {
Text("Cover your mouth and nose when coughing or sneezing")
}.padding(40)
Toggle(isOn: $quarantineToggle) {
Text("Quarantine")
}.padding(40)
if !washingHandsToggle && !wearingMaskToggle && !coverMouthToggle && !quarantineToggle {
self.r0 = 1.0
}else if !washingHandsToggle && !wearingMaskToggle && coverMouthToggle && !quarantineToggle {
self.r0 = 2.0
}else if washingHandsToggle && !wearingMaskToggle && !coverMouthToggle && !quarantineToggle {
self.r0 = 3.0
}else if !washingHandsToggle && wearingMaskToggle && !coverMouthToggle && !quarantineToggle {
self.r0 = 4.0
}else if washingHandsToggle && !wearingMaskToggle && coverMouthToggle && !quarantineToggle {
self.r0 = 5.0
}else if !washingHandsToggle && wearingMaskToggle && coverMouthToggle && !quarantineToggle {
self.r0 = 6.0
}else if washingHandsToggle && wearingMaskToggle && !coverMouthToggle && !quarantineToggle {
self.r0 = 7.0
}else if washingHandsToggle && wearingMaskToggle && coverMouthToggle && !quarantineToggle {
self.r0 = 8.0
}else if !washingHandsToggle && !wearingMaskToggle && !coverMouthToggle && quarantineToggle {
self.r0 = 9.0
}else if !washingHandsToggle && !wearingMaskToggle && coverMouthToggle && quarantineToggle {
self.r0 = 10.0
}else if washingHandsToggle && !wearingMaskToggle && !coverMouthToggle && quarantineToggle {
self.r0 = 11.0
}else if !washingHandsToggle && wearingMaskToggle && !coverMouthToggle && quarantineToggle {
self.r0 = 12.0
}else if washingHandsToggle && !wearingMaskToggle && coverMouthToggle && quarantineToggle {
self.r0 = 13.0
}else if !washingHandsToggle && wearingMaskToggle && coverMouthToggle && quarantineToggle {
self.r0 = 14.0
}else if washingHandsToggle && wearingMaskToggle && !coverMouthToggle && quarantineToggle {
self.r0 = 15.0
}else {
self.r0 = 16.0
}