Created
September 7, 2016 10:56
-
-
Save Melonbwead/ee72ffe5cfd80b26cddda2e81b91ae52 to your computer and use it in GitHub Desktop.
Days of the week using enum in swift.
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 WeekDayNumber { | |
case Monday, Tuesday, Wednesday, Thursday, Friday, Caturday, Saturday, Sunday | |
static var dayValuesInChinese = [] | |
func getDayInNumber() -> Int { | |
switch self { | |
case .Monday: | |
return 1 | |
case .Tuesday: | |
return 2 | |
case .Wednesday: | |
return 3 | |
case .Thursday: | |
return 4 | |
case .Friday: | |
return 5 | |
case .Caturday: | |
return 6 | |
case .Saturday: | |
return 6 | |
case .Sunday: | |
return 7 | |
} | |
} | |
func getDayInChinese() -> String { | |
switch self { | |
case .Monday: | |
return "星期一" | |
case .Tuesday: | |
return "星期二" | |
case .Wednesday: | |
return "星期三" | |
case .Thursday: | |
return "星期四" | |
case .Friday: | |
return "星期五" | |
case .Caturday: | |
return "星期六" | |
case .Saturday: | |
return "星期六" | |
case .Sunday: | |
return "星期日" | |
} | |
} | |
} | |
var worstDay = WeekDayNumber.Monday | |
worstDay.getDayInNumber() | |
worstDay.getDayInChinese() | |
var bestDay = WeekDayNumber.Saturday | |
bestDay.getDayInNumber() | |
bestDay.getDayInChinese() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment