4

我正在尝试通过EKEventStore在 iOS8 中使用 Swift 来获取事件列表,据我所知,文档尚未更新。

这就是我想要做的:

let eventStore =  EKEventStore()

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

这是我得到的错误:

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

你知道如何在 Swift 中正确使用方法或处理程序吗?

4

1 回答 1

6

请试试这个:

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

另一个变体是:

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

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

        // put your handler code here
        })
}
于 2014-07-11T11:56:34.267 回答