我目前很新的雨燕,我想知道,如果下面的代码可以被优化/缩短以任何方式:交换枚举值斯威夫特
enum CardOrientation {
case Horizontal, Vertical
}
func toggleCurrentCardOrientation() {
switch currentCardOrientation {
case .Horizontal: currentCardOrientation = .Vertical
case .Vertical: currentCardOrientation = .Horizontal
}
}
让我们假设CardOrientation
将永远只是有这些两个可能的值和每个呼叫toggleCurrentCardOrientation
都应该在每个值之间切换。
+1提供两种不同的方法。起初我正在考虑使用Bool,但我总觉得能够使用令人敬畏的“.Vertical”语法,这使得它更加明显地发生了什么。 – BastiBen 2014-09-22 17:13:39