1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| enum Arithmetic { case addition, subtraction, multiplication, division func calculate(_ firstNumber: Double, _ secondNumber: Double) -> Double { switch self { case .addition: return firstNumber + secondNumber case .subtraction: return firstNumber - secondNumber case .multiplication: return firstNumber * secondNumber case .division: return firstNumber / secondNumber } } }
Arithmetic.addition.calculate(10, 5)
Arithmetic.subtraction.calculate(10, 5)
Arithmetic.multiplication.calculate(10, 5)
Arithmetic.division.calculate(10, 5)
|