Created
April 28, 2016 23:01
-
-
Save corybohon/22a144627938aba92e8142585878cb14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func addTodoItem(item: TodoItem) { | |
self.storedTodos.append(item) | |
self.createNotification(item.todoName, date: item.todoDueDate) | |
self.saveAndNotify() | |
} | |
func removeTodoItem(item: TodoItem) { | |
if self.storedTodos.contains(item) { | |
if let indexToRemove = self.storedTodos.indexOf(item) { | |
self.storedTodos.removeAtIndex(indexToRemove) | |
self.removeNotification(item.todoName, date: item.todoDueDate) | |
self.saveAndNotify() | |
} | |
} | |
} | |
func createNotification(name: String, date: NSDate) { | |
let notification: NSUserNotification = NSUserNotification() | |
notification.deliveryDate = date | |
notification.title = "Reminderz" | |
notification.subtitle = name | |
NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification(notification) | |
} | |
func removeNotification(name: String, date: NSDate) { | |
for notification in NSUserNotificationCenter.defaultUserNotificationCenter().scheduledNotifications { | |
if notification.subtitle! == name && (notification.deliveryDate?.isEqualToDate(date))! { | |
NSUserNotificationCenter.defaultUserNotificationCenter().removeScheduledNotification(notification) | |
} | |
} | |
} | |
func removeOldNotifications() { | |
NSUserNotificationCenter.defaultUserNotificationCenter().removeAllDeliveredNotifications() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment