ios - How can I find the next weekend Swift -


i have app in want show data when it's saturday or sunday. have segmented control , if press 1 of option (which weekend) want check if saturday or sunday first weekend.

this i've done first option in segmented control take current date

dateevent variable take check if currentdate currentdate declared currentdate

  if  dateevent.earlierdate(self.currentdate).isequaltodate(self.currentdate){    if nscalendar.currentcalendar().isdate(dateevent, equaltodate: self.currentdate, tounitgranularity: .day){                                  //do                             }                          } 

first find number of days add nsdatecomponents weekday property , can use datebyaddingcomponents(_:todate:options:).

let today = nsdate() let calendar = nscalendar.currentcalendar()  let todayweekday = calendar.component(.weekday, fromdate: today)  let addweekdays = 7 - todayweekday  // 7: saturday number var components = nsdatecomponents() components.weekday = addweekdays  let nextsaturday = calendar.datebyaddingcomponents(components, todate: today, options: .matchfirst) 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -