Swift Update EKEvent

259 Views Asked by At

Hi I am trying to update an EKEvent. I have successfully been able to add and delete an event by using the same logic.

To add Event I used -> try store.save(event, span: .thisEvent, commit: true)

How do I updated Event ???

To delete Event I used -> try store.remove(calendar, span: .thisEvent, commit: true)

I have the correct EKEvent Identifier and EKEvent when the updatedEvent() method is called, and I am able to print the event in that function.

When this function is called it fails to update the new event, and prints "Event Could not be updated".

I could not find a store.update(event, span: .thisEvent, commit: true) or something along the lines of that.

Any help is much appropriated thanks!

    public func updateEvent(title: String, startDate: Date, isAllDay: Bool , timeZone: String,address: String, note: String, store: EKEventStore, event: EKEvent){
        

          let event = store.event(withIdentifier: event.eventIdentifier)
          let endDate = startDate.addingTimeInterval(2 * 60 * 60)
            event?.title = title
            event?.isAllDay = isAllDay
            event?.location = address
            event?.startDate = startDate
            event?.endDate = endDate
            event?.notes = note
            event?.calendar = store.defaultCalendarForNewEvents
        
        do {
           
            try store.save(event!, span: .thisEvent, commit: true)
            
        } catch {
            print("Event Could not be updated")
        }
    }
0

There are 0 best solutions below