1

I am trying to create some date objects.

var gregorian:NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!;

var unit : NSCalendarUnit = (NSCalendarUnit.YearCalendarUnit|NSCalendarUnit.MonthCalendarUnit|NSCalendarUnit.DayCalendarUnit|NSCalendarUnit.HourCalendarUnit|NSCalendarUnit.MinuteCalendarUnit);
var interval:Double = Double(i)*60*60*24;
var tomorrow:NSDate = NSDate().dateByAddingTimeInterval(interval);

var comps:NSDateComponents = gregorian.components(unit, fromDate: tomorrow);

comps.setValue(17, forComponent: NSCalendarUnit.HourCalendarUnit);
var five_tomorrow : NSDate = gregorian.dateFromComponents(comps)!;

comps.setValue(19, forComponent: NSCalendarUnit.HourCalendarUnit);
var seven_tomorrow : NSDate = gregorian.dateFromComponents(comps)!;

comps.setValue(21, forComponent: NSCalendarUnit.HourCalendarUnit);
var nine_tomorrow : NSDate = gregorian.dateFromComponents(comps)!;

This seems to work fine on my iOS8 phone. But on my iOS7 device I print the dates and get 2015-03-03 19:33:00 MST for all of the them. Any guesses as to why this is happening?

Edit: What I am trying to do is get the date for around 5:00, 7:00, 9:00, and 10:00 pm tomorrow to set a local notification. I don't care so much about the minutes.

Chase Roberts
  • 9,082
  • 13
  • 73
  • 131

1 Answers1

0

It's used only on ios 8.0 and later.

@availability(iOS, introduced=8.0)
func setValue(value: Int, forComponent unit: NSCalendarUnit)
Huynh Inc
  • 2,010
  • 1
  • 25
  • 42