EKCADErrorDomain using calendarWithIdentifier

谁说我不能喝 提交于 2019-11-30 06:53:30

I'm stumped on the same silly thing too.

I just looped over an array of calendars and match according to the identifier. It's not elegant, but it works and the average user probably have less than 10 calendars so...oh well..

here's my workaround in swift

func createEvent(){
    var event = EKEvent(eventStore: self.eventStore)
    var calendar : EKCalendar!
    let calendars : [EKCalendar] = self.eventStore.calendarsForEntityType(EKEntityTypeEvent) as [EKCalendar]

    for aCal in calendars
    {
        if(aCal.calendarIdentifier == self.calendarIdentifier)
        {
            calendar = aCal
            break
        }
    } ...continue to do stuff to events....

}

Swift 4.2

Instead of

let matchedCal = eventStore
    .calendar(withIdentifier: calendarIdentifier)

You can use:

let matchedCal = eventStore
    .calendars(for: .event)
    .first(where: { $0.calendarIdentifier == calendarIdentifier })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!