1

I'm trying to get access to a user's calendars via EventKit using Swift 2. In digging around online, I've found a few examples showing similar implementations to this answer on another SO question.

The error I keep hitting is

Use of unresolved identifier 'EKEntityTypeEvent'

In my viewDidLoad() -

let eventStore = EKEventStore()

switch EKEventStore.authorizationStatusForEntityType(EKEntityTypeEvent) {        
case .Authorized:
    insertEvent(eventStore)
case .Denied:
    print("Access denied")
case .NotDetermined:
    eventStore.requestAccessToEntityType(EKEntityTypeEvent, completion:
        {[weak self] (granted: Bool, error: NSError!) -> Void in
            if granted {
                self!.insertEvent(eventStore)
            } else {
                print("Access denied")
            }
        })
default:
    print("Case Default")
}

Any ideas on this error?

I'm running El Capitan / XCode 7 Beta 3.

Community
  • 1
  • 1
Emile
  • 3,464
  • 8
  • 46
  • 77

1 Answers1

8

Okay, there are mainly two things wrong here - the first has already been discussed in the comments.

First: use .Event or EKEntityType.Event instead of the EKEntityTypeEvent.

Second: change the declaration of the completion handler to accept a NSError? instead of NSError! because the actual completion handler is defined this way.

luk2302
  • 55,258
  • 23
  • 97
  • 137
  • requestAccessToEntityType should fire the request to access calendar events correct? While it does compile, no request notification appears. Thoughts? – Emile Jul 18 '15 at 21:05
  • @Emile no idea, sry :/ you might want to ask a different question for that issue... – luk2302 Jul 18 '15 at 21:17