Skip to content

Instantly share code, notes, and snippets.

@helloworldsmart
Last active November 5, 2016 09:21
Show Gist options
  • Select an option

  • Save helloworldsmart/7b6058b4b1dc5f9ce2777bd93f5d39eb to your computer and use it in GitHub Desktop.

Select an option

Save helloworldsmart/7b6058b4b1dc5f9ce2777bd93f5d39eb to your computer and use it in GitHub Desktop.
Optional便利貼
```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