Я пытаюсь реализовать тот же код в https://www.andrewcbancroft.com/2015/06/17/creating-calendars-with-event-kit-and-swift/,, но получаю сообщение об ошибке «ошибка json: произошла непредвиденная ошибка».Я разрабатываю этот проект для macOS.
Это мой следующий код,
@IBAction func addPressed(_ sender: NSButton) {
// Create an Event Store instance
let eventStore = EKEventStore();
// Use Event Store to create a new calendar instance
// Configure its title
let newCalendar = EKCalendar(for: .event, eventStore: eventStore)
// Probably want to prevent someone from saving a calendar
// if they don't type in a name...
newCalendar.title = "DCU"
// Access list of available sources from the Event Store
let sourcesInEventStore = eventStore.sources
// Filter the available sources and select the "Local" source to assign to the new calendar's
// source property
newCalendar.source = sourcesInEventStore.filter{
(source: EKSource) -> Bool in
source.sourceType.rawValue == EKSourceType.local.rawValue
}.first!
// Save the calendar using the Event Store instance
do {
try eventStore.saveCalendar(newCalendar, commit: true)
} catch {
print("json error: \(error.localizedDescription)")
}
}
Когда я собираю проект и нажимаю кнопку «Выполнить», он выдает ошибку «json error: Произошла непредвиденная ошибка. ".Когда я пытаюсь добавить событие в defaultcalendar, выдается сообщение об ошибке «ошибка json: календарь не установлен».Я перепробовал все доступные источники в Интернете, но не смог найти решение.Каким-то образом ни eventStore.save, ни eventStore.saveCalendar не работают для меня.Может кто-нибудь, пожалуйста, дайте мне знать, где я могу пойти не так?