我正在尝试通过在 iOS8 中使用 Swift 使用 EKEventStore
获取事件列表,据我所知,文档尚未更新。
这就是我想要做的:
let eventStore = EKEventStore()
eventStore.requestAccessToEntityType(EKEntityType(), EKEventStoreRequestAccessCompletionHandler(Bool(), NSError(){}))
这是我得到的错误:
“EKEventStoreRequestAccessCompletionHandler”不能用“(Bool, NSError)”构造
您知道如何在 Swift 中正确使用方法或处理程序吗?
最佳答案
请试试这个:
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
})
}
关于swift - 如何在 Swift iOS 8 中使用 requestAccessToEntityType 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24692605/