You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
// Copyright © 2015 Abhishek Banthia |
|
|
|
import Cocoa |
|
import EventKit |
|
|
|
class EventCenter: NSObject { |
|
private static var shared = EventCenter() |
|
|
|
let store = EKEventStore() |
|
|
|
var calendar: EKCalendar? |
|
|
|
var autoupdatingCalendar = NSCalendar.autoupdatingCurrent |
|
|
|
var eventsForDate: [Date: [EventInfo]] = [:] |
|
|
|
var filteredEvents: [Date: [EventInfo]] = [:] |
|
|
|
@discardableResult @objc class func sharedCenter() -> EventCenter { |
|
return shared |
|
} |
|
|
|
override init() { |
|
super.init() |
|
refetchAll() |
|
NotificationCenter.default.addObserver(self, |
|
selector: #selector(EventCenter.eventStoreDidChange(_:)), |
|
name: .EKEventStoreChanged, |
|
object: nil) |
|
} |
|
|
|
@objc func eventStoreDidChange(_ sender: Any) { |
|
refetchAll() |
|
} |
|
|
|
private func refetchAll() { |
|
print("\nRefetching events from the store") |
|
eventsForDate = [:] |
|
filteredEvents = [:] |
|
|
|
// We get events for a 120 day period. |
|
// If the user uses a calendar often, this will be called frequently |
|
fetchEvents(-40, 80) |
|
} |
|
}
|
|
|