4

I'm trying to get a list of events by using EKEventStore using Swift in iOS8, and the documentation is not updated yet as far as I can tell.

This is what I'm trying to do:

let eventStore =  EKEventStore()

eventStore.requestAccessToEntityType(EKEntityType(), EKEventStoreRequestAccessCompletionHandler(Bool(), NSError(){}))

This is the error I get:

'EKEventStoreRequestAccessCompletionHandler' is not constructible with '(Bool, NSError)

Do you know how can I use the method or the handler correctly in Swift?

Dhara
  • 6,587
  • 2
  • 31
  • 46
shila
  • 95
  • 2
  • 9

1 Answers1

6

Try this please:

func handler(granted: Bool, error: NSError!) {
    // put your handler code here
}

@IBAction func click(sender: AnyObject) {
    let eventStore = EKEventStore()

    // 'EKEntityTypeReminder' or 'EKEntityTypeEvent'
    eventStore.requestAccessToEntityType(EKEntityTypeEvent, completion: handler) 
}

Another variant is:

@IBAction func click(sender: AnyObject) {
    let eventStore = EKEventStore()

    // 'EKEntityTypeReminder' or 'EKEntityTypeEvent'
    eventStore.requestAccessToEntityType(EKEntityTypeEvent, completion: {
        granted, error in

        // put your handler code here
        })
}
Alex Peda
  • 4,210
  • 3
  • 22
  • 31