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

Lists in Python -

android - can not access to progress bar in an other activity -

html - Not able to access next element of an array javascript -