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?
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
})
}
来源:https://stackoverflow.com/questions/24692605/how-to-use-requestaccesstoentitytype-method-in-swift-ios-8