(Swift) 올해 크리스마스는 무슨 요일인가?

NSDate 관련 포스팅에서 주구장창 써먹었던 소재.

코드는 아래에…

/* 결과보기 : http://swiftstub.com/345157923 */
enum Weekday: Int, CustomStringConvertible {
case Sun = 1
case Mon, Tue, Wed, Thu, Fri, Sat
var description: String {
switch self {
case .Sun: return "Sunday"
case .Mon: return "Monday"
case .Tue: return "Tuesday"
case .Wed: return "Wedenesday"
case .Thu: return "Thursday"
case .Fri: return "Friday"
case .Sat: return "Saturday"
}
}
}
func whatIsTheDayOfThisChristmas() {
if let cal = NSCalendar(identifier: NSCalendarIdentifierGregorian),
case let thisYear: Int =
cal.components([.Year], fromDate:NSDate()).year {
let comps = NSDateComponents()
comps.year = thisYear
comps.month = 12
comps.day = 25
let christmas = cal.dateFromComponents(comps)!
let c = cal.components([.Day, .Weekday], fromDate:christmas)
print(Weekday(rawValue: c.weekday)!)
}
}
whatIsTheDayOfThisChristmas()

view raw
xmas.swift
hosted with ❤ by GitHub

생각해보니 date components 만들 때 옵션이 OptionSet 타입으로 바뀌었네…