I'm trying to trigger notification on specific saved time in database and on specific day which is Friday as shown below, but every time I try to save new reminder it tells me unexpectedly found nil while unwrapping an Optional value
and I'm sure it contains data and it's not nil even though I tried to handle nil, still the app crash, however when I try to fire notification without combining dates like this localNotification.fireDate = reminders.time!
the app is not crashed and it works just fine.
I guess the problem in combineDate function, how I can solve this problem?
func combineDate(time: NSDate?) -> NSDate{
let gregorianCalendar: NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
let time: NSDateComponents = gregorianCalendar.components([.Hour, .Minute, .Second], fromDate: time!)
time.timeZone = NSTimeZone.systemTimeZone()
let timeCombiner: NSDateComponents = NSDateComponents()
timeCombiner.timeZone = NSTimeZone.systemTimeZone()
timeCombiner.hour = time.hour
timeCombiner.minute = time.minute
timeCombiner.second = 00
timeCombiner.weekday = 6
let combinedDate: NSDate = gregorianCalendar.dateFromComponents(components3)!
return combinedDate
}
func createLocalNotification(){
let localNotification = UILocalNotification()
localNotification.timeZone = NSTimeZone.systemTimeZone()
localNotification.fireDate = combineDate(reminders.time!)
localNotification.alertBody = reminders.name!
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}