Skip to content

Instantly share code, notes, and snippets.

@motokiee
Created December 14, 2015 10:33
Show Gist options
  • Save motokiee/85fe63fe03e02e20f264 to your computer and use it in GitHub Desktop.
Save motokiee/85fe63fe03e02e20f264 to your computer and use it in GitHub Desktop.
typealias PaymentType = (Bool, Bool, Bool)
func getPayAmountEasySwitch(payment: PaymentType) -> Double {
switch (payment.0, payment.1, payment.2) {
case (true, _, _):
return 0.0
case (_, true, _):
return 1.0
case (_, _, true):
return 2.0
default:
return 3.0
}
}
enum Payment {
case Dead, Separated, Retired, Other
}
func amount(payment: Payment) -> Double {
switch payment {
case .Dead:
return 0.0
case .Separated:
return 1.0
case .Retired:
return 2.0
case .Other:
return 3.0
}
}
func contains(names:[String]) -> Bool {
return names.filter { $0 == "Soichiro" || $0 == "Nagao" }.count > 0
}
protocol Vehicle {
func getSpeed() -> Int
}
struct Car: Vehicle {
func getSpeed() -> Int {
return 100
}
}
struct Bike: Vehicle {
func getSpeed() -> Int {
return 120
}
}
struct Bus: Vehicle {
func getSpeed() -> Int {
return 60
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment