我正在尝试使用 Swift 2 通过 EventKit 访问用户的日历。在网上搜索时,我发现了一个 few examples显示与此类似的实现 answer在另一个SO question .
我一直打的错误是
Use of unresolved identifier 'EKEntityTypeEvent'
在我的 viewDidLoad() 中 -
let eventStore = EKEventStore()
switch EKEventStore.authorizationStatusForEntityType(EKEntityTypeEvent) {
case .Authorized:
insertEvent(eventStore)
case .Denied:
print("Access denied")
case .NotDetermined:
eventStore.requestAccessToEntityType(EKEntityTypeEvent, completion:
{[weak self] (granted: Bool, error: NSError!) -> Void in
if granted {
self!.insertEvent(eventStore)
} else {
print("Access denied")
}
})
default:
print("Case Default")
}
关于这个错误有什么想法吗?
我正在运行 El Capitan/XCode 7 Beta 3。
最佳答案
好的,这里主要有两点错误 - 第一点已经在评论中讨论过。
首先:使用 .Event
或 EKEntityType.Event
而不是 EKEntityTypeEvent
。
第二:更改完成处理程序的声明以接受 NSError?
而不是 NSError!
因为 the actual completion handler是这样定义的。
关于ios - 错误 "Use of unresolved identifier ' EKEntityTypeEvent'“尝试访问日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31494874/