I'm setting up some local notifications as reminders. So far I've been able to set a non repeating notification which triggers from a date picked from a datePicker.
let dateformatter = DateFormatter()
dateformatter.dateStyle = DateFormatter.Style.medium
dateformatter.timeStyle = DateFormatter.Style.short
let dateFromString = dateformatter.date(from: selectDateTextField.text!)
let fireDateOfNotification: Date = dateFromString!
//if permission allowed
let content = UNMutableNotificationContent()
content.title = notifTitleTextField.text!
content.body = notifNoteTextView.text
content.sound = UNNotificationSound.default()
let triggerDate = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second,], from: fireDateOfNotification)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate,
repeats: false)
//Schedule the Notification
let titleNospace = notifTitleTextField.text?.replacingOccurrences(of: " ", with: "")
let identifier = titleNospace
let request = UNNotificationRequest(identifier: identifier!, content: content, trigger: trigger)
self.center.add(request, withCompletionHandler: { (error) in
if let error = error {
print(error.localizedDescription)
}
})
Now i would like the user to pick from a list (or a Picker) the repeating interval (hourly, daily, weekly, monthly, yearly or every x days). Is there a simple way to do so or i need to create a custom class? is it correct to make it through a series of if else statement? (it seems to me a bit off, doesn't really seems to be the correct way) Thanks.