Created
May 21, 2018 12:01
-
-
Save fassko/6eb8a808120bc83d8b44db4e2cd839f4 to your computer and use it in GitHub Desktop.
Swift switch value bindings
This file contains hidden or 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
/// Wind speed with direction | |
enum WindSpeed { | |
case north(Double) | |
case east(Double) | |
case south(Double) | |
case west(Double) | |
} | |
let direction = WindSpeed.north(3.6) | |
// Switch with value binding before matching pattern | |
switch direction { | |
case let .north(speed): | |
print(speed) | |
default: | |
print("default") | |
} | |
// Switch with value binding inside matching pattern | |
switch direction { | |
case .north(let speed): | |
print(speed) | |
default: | |
print("default") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment