EKCADErrorDomain using calendarWithIdentifier

前端 未结 2 1821
自闭症患者
自闭症患者 2020-12-30 07:16

In my iOS app i used to access calendar with the following method:

EKCalendar* cal = [eventStore calendarWithIdentifier:[calendarIDs objectAtIndex:i]];


        
相关标签:
2条回答
  • 2020-12-30 07:33

    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....
    
    }
    
    0 讨论(0)
  • 2020-12-30 07:45

    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 })
    
    0 讨论(0)
提交回复
热议问题