Last active
April 9, 2019 09:24
-
-
Save bouchtaoui-dev/8083f2e7200d07cce0212ac0c24dad7e to your computer and use it in GitHub Desktop.
How to improve this snippet of Swift code. I have like more than 10 checkboxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var socialData: SocialData? = storage.data("social") | |
... | |
... | |
// checkLiveAudio = NSButton (CheckBox button) | |
... | |
if let data = socialData { | |
if data.isAudioEnabled() { | |
checkLiveAudio.state = NSControl.StateValue.on | |
} else { | |
checkLiveAudio.state = NSControl.StateValue.off | |
} | |
if data.isAudioPermissionEnabled() { | |
checkAudioPermission.state = NSControl.StateValue.on | |
} else { | |
checkAudioPermission.state = NSControl.StateValue.off | |
} | |
} | |
... | |
... | |
// 10 more checkboxes | |
// This is getting annoying | |
// I hoped to do something like this: | |
checkLiveAudio.state = data.isAudioEnabled() ? NSControl.StateValue.on : NSControl.StateValue.off | |
// Reducing from 5 to 1 line of code, but compiler complains with some errors | |
// data.isAudioEnabled() returns either false or true, there's no nil or other values, just false or true. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment