Last active
November 5, 2016 09:21
-
-
Save helloworldsmart/7b6058b4b1dc5f9ce2777bd93f5d39eb to your computer and use it in GitHub Desktop.
Optional便利貼
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
| ```swift= | |
| func perform(operation:String, a:Double, b:Double) -> Double! { | |
| var result:Double? | |
| switch operation { | |
| case "+": | |
| result = a + b | |
| case "-": | |
| result = a - b | |
| case "/": | |
| result = a / b | |
| case "*": | |
| result = a * b | |
| default: | |
| print("Error operation") | |
| } | |
| // print("Performing", operation, "on", a, "and", b) | |
| return result | |
| } | |
| if let result = perform(operation: "like", a: 3.0, b: 4.0) { | |
| print(result) | |
| } else { | |
| print("error") | |
| } | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment