0

I tried to request access to the calendar using following code:

EKEventStore().requestAccess(to: EKEntityType.event, completion: {
    (success: Bool, error: NSError!) in

    print("Got permission = \(success); error = \(error)")
 })

Xcode wants to add as! EKEventStoreRequestAccessCompletionHandler because it says

Cannot convet value of type (Bool, NSError!) ...".

But when I add this the app crashes with EXC_BAD_INSTRUCTION and no further explanation. Any ideas whats wrong here?

Thanks a lot

Nirav D
  • 71,513
  • 12
  • 161
  • 183
MotoxX
  • 917
  • 1
  • 7
  • 13

1 Answers1

6

In Swift 3 you need to use Error instead of NSError check Apple documentation for more detail.

EKEventStore().requestAccess(to: EKEntityType.event, completion: {
    (success: Bool, error: Error?) in  

    print("Got permission = \(success); error = \(error)")

})
Nirav D
  • 71,513
  • 12
  • 161
  • 183