如何在Swift iOS 8中使用requestAccessToEntityType方法 [英] How to use requestAccessToEntityType method in Swift iOS 8
本文介绍了如何在Swift iOS 8中使用requestAccessToEntityType方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用iOS8中的Swift使用 EKEventStore
获取事件列表,据我所知,文档尚未更新。
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.
这就是我要做的事情:
let eventStore = EKEventStore()
eventStore.requestAccessToEntityType(EKEntityType(), EKEventStoreRequestAccessCompletionHandler(Bool(), NSError(){}))
这是我得到的错误:
'EKEventStoreRequestAccessCompletionHandler'不能与'构造'(Bool, NSError)
你知道如何在Swift中正确使用方法或处理程序吗?
Do you know how can I use the method or the handler correctly in 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 iOS 8中使用requestAccessToEntityType方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文