Search code examples
objective-ccocoa-toucheventkit

How to create a Calendar of a specific type?


How can I create a calendar of a specific type? All calendars created with + calendarWithEventStore: are created with type Local:

EKEventStore *store = [[EKEventStore alloc] init];
EKCalendar *cal = [EKCalendar calendarWithEventStore:store];

Solution

  • You can enumerate over the available types and pull the one you want.

    EKCalendar* cal = [EKCalendar calendarWithEventStore: self.eventStore];
    
    EKSource* sourceForType = nil;
    
    for (EKSource* src in self.eventStore.sources)
    {
        if (src.sourceType == calType)
        {
            sourceForType = src;
        }
    }
    
    cal.source = sourceForType;