Created
May 2, 2018 11:45
-
-
Save EJSohn/be48f34d8f403f80cb25afcd8a2a56fb to your computer and use it in GitHub Desktop.
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
| var directionToHead = CompassPoint.west | |
| // or | |
| var directionToHead: CompassPoint = .west |
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
| switch directionToHead { | |
| case .west: | |
| print("do something") | |
| case .north: | |
| print("do another thing") | |
| default: | |
| break | |
| } |
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
| // Enumeration of type Fruit. | |
| enum Fruit: Int { | |
| case apple = 1000 | |
| case banana = 500 | |
| case grape = 2500 | |
| } | |
| // declare variable. | |
| let orderedFruit: Fruit = .apple | |
| switch orderedFruit { | |
| default: | |
| print("\(orderedFruit.rawValue)원 주세요!") | |
| } |
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
| enum Cloud { | |
| case cirrus | |
| case cumulus | |
| case altocumulus | |
| case cumulonimbus | |
| } | |
| enum WeatherCondition { | |
| case sunny(temperature: Float) | |
| case rainy(inchesPerHour: Float) | |
| case cloudy(cloudType: Cloud, windSpeed: Float) | |
| } |
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
| // declare variables. | |
| var today = WeatherCondition.sunny(24) | |
| var yesterday = WeatherCondition.cloudy(Cloud.cirrus, 10) | |
| switch today { | |
| case .sunny(let temperature): | |
| print("today's temperature is \(temperature).") | |
| case .rainy(let inchesPerHour): | |
| print("\(inchesPerHour) inches of rainwater.") | |
| case .cloudy(let cloudType, let windSpeed): | |
| switch cloudType { | |
| case .cirrus: | |
| print("it's cloudy cirrus.") | |
| default: | |
| print("somethig blah..") | |
| } | |
| print("wind speed: \(windSpeed)") | |
| } |
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
| enum ArithmeticExpression { | |
| case number(Int) | |
| indirect case addition(ArithmeticExpression, ArithmeticExpression) | |
| indirect case multiplication(ArithmeticExpression, ArithmeticExpression) | |
| } |
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
| func evaluate(_ expression: ArithmeticExpression) -> Int { | |
| switch expression { | |
| case let .number(value): | |
| return value | |
| case let .addition(left, right): | |
| return evaluate(left) + evaluate(right) | |
| case let .multiplication(left, right): | |
| return evaluate(left) * evaluate(right) | |
| } | |
| } |
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
| public enum Result<Value> { | |
| case Success(Value) | |
| case Failure(NSData?, ErrorType) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment