无法将类型转换为预期的参数类型

时间:2015-12-22 10:59:56

标签: ekeventstore

let eventStore = EKEventStore()


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

我收到错误:无法转换类型的值'(bool,nserror!) - > void'预期的论证类型' ekeventstorerequestaccescompletionhandler'

在这一行:

eventStore.requestAccessToEntityType(EKEntityType.Event, completion:
        {[weak self] (granted: Bool, error: NSError!) -> Void in

1 个答案:

答案 0 :(得分:1)

尝试删除[弱自我],在我的情况下,这个有效:

eventStore.requestAccessToEntityType(EKEntityType.Event, completion: {
        (accessGranted: Bool, error: NSError?) in

        if accessGranted && (error == nil) {
            dispatch_async(dispatch_get_main_queue(), { completion(true) })
        } else {
            dispatch_async(dispatch_get_main_queue(), { completion(false) })
        }
    })