0

I have successfully saved the events of my application to local calendar using Eventkit but now I want to delete the events that I have saved using my application only. But the below code give me list of all events saved on calendar but I just want to delete my own saved event. How can I do that?

 let predicate = eventStore.predicateForEvents(withStart: start, end: endDate, calendars: [calendar])       
 let events = eventStore.events(matching: predicate)
Bhavik Modi
  • 1,517
  • 14
  • 29
Shipra Gupta
  • 171
  • 1
  • 2
  • 10

2 Answers2

2

When saving events to calendar you can store EKEvent's eventIdentifier property.

And when you want to delete events that were created by you, you can query them by identifiers.

Note: store eventIdentfier only after calling eventStore.save(...) method.

Juri Noga
  • 4,363
  • 7
  • 38
  • 51
  • Thanks yes doing same by saving array of saved events identifier in userdefalut and fetch those when I want to delete :) – Shipra Gupta May 17 '19 at 09:23
0

You can only remove event by comparing Event Title with fetched events:

    var allEvents: [EKEvent] = []

    let eventStore = EKEventStore()
    let calendars = eventStore.calendars(for: .event)

    for calendar in calendars {

        // end date (about) one year from now
        let endDate = Date(timeIntervalSinceNow: 60*60*24*365)

        let predicate = eventStore.predicateForEvents(withStart: Date(), end: endDate as Date, calendars: [calendar])

        let events = eventStore.events(matching: predicate)

        allEvents.append(contentsOf: events)

    }

    for event in allEvents {
        print(event.title, "in", event.calendar.title)
    }
Bhavik Modi
  • 1,517
  • 14
  • 29