新增活動

建立事件物件

迅速

var event = EKEvent(eventStore: eventStore)

Objective-C

EKEvent *event = [EKEvent initWithEventStore:eventStore];

設定相關的日曆,標題和日期

迅速

event.calendar = calendar
event.title = "Event Title"
event.startDate = startDate //assuming startDate is a valid NSDate object
event.endDate = endDate //assuming endDate is a valid NSDate object

將事件新增到日曆

迅速

try {
    do eventStore.saveEvent(event, span: EKSpan.ThisEvent)
} catch let error as NSError {
    //error
}

Objective-C

NSError *error;
BOOL *result = [eventStore saveEvent:event span:EKSpanThisEvent error:&error];
if (result == NO){
    //error
}