如何执行基于天的功能?

How to execute function based on day?

我有一个函数,如下所示,它根据小时执行函数。我如何修改它以也根据星期几执行?

let date = NSDate()
    let calendar = NSCalendar.currentCalendar()
    let components = calendar.components(.CalendarUnitHour, fromDate: date)
    let hour = components.hour


    if(hour >= 9 && hour <= 17)
    {
        //set your image 'open image'
        println("Open")
    }
    else{
         //set your image 'close image'
        println("closed")
    }

NSCalendarUnit 可以用 UInt 初始化,因此这为您提供了所有可能的组件:

var flags = NSCalendarUnit(UInt.max)
let components = calendar.components(flags, fromDate: date)
let day=components.day
let hour = components.hour