How to use requestAccessToEntityType method in Swift iOS 8

ekeventstore, eventkit, ios8, swift

Solution

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
        })
}

Problem

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?

Original source