Reputation: 11672
I want to set notification at the time (hour, minute) that I set. But It show error:
func notification(story: Story) {
let dateComponents = NSDateComponents.init()
dateComponents.weekday = 5
dateComponents.hour = story.remindeAtHour
dateComponents.minute = story.remindeAtMinute
let notification = UILocalNotification()
notification.alertAction = "Title"
notification.alertBody = "It's time to take a photo"
notification.repeatInterval = NSCalendarUnit.WeekOfYear
notification.fireDate = dateComponents.calendar
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
Upvotes: 0
Views: 281
Reputation: 131418
As Paul w points out in his comment, the error message is telling you what's wrong.
You need to set the notification's fireDate property to a date (An NSDate
). You need a method that will convert date components to an NSDate
. How about the NSCalendar method dateFromComponents:
?
Upvotes: 1