'Add & Cancel buttons in EventKit not working

Im using event kit to create a reminder, but when I press add or cancel the window does not close. if I go into the calendars app I can see the item in there. I've tried adding "editviewDelegate = self" but I always get an error saying "Cannot assign value of type 'ViewController?' to type 'EKEventEditViewDelegate"

import UIKit import EventKit import EventKitUI

class ViewController: UIViewController, EKEventViewDelegate {

func eventViewController(_ controller: EKEventViewController, didCompleteWith action: EKEventViewAction) {
    controller.dismiss(animated: true, completion: nil)
}

let store = EKEventStore()


override func viewDidLoad() {
    super.viewDidLoad()
    
    navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addnew))
}

@objc func addnew() {
    
    store.requestAccess(to: .event) { [weak self] success, error in
        if success, error == nil {
            DispatchQueue.main.async {
                guard let store = self?.store else   {return}
                           
                let othervc = EKEventEditViewController()
                othervc.eventStore = store
                othervc.event = EKEvent(eventStore: store)
                self?.present(othervc, animated: true, completion: nil)
                                
            }
        }
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source