Created
December 14, 2015 10:33
-
-
Save motokiee/85fe63fe03e02e20f264 to your computer and use it in GitHub Desktop.
inspired from Qiita article http://qiita.com/sohichiro/items/76208546138ffbe4e852
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
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