ios - 错误 "Use of unresolved identifier ' EKEntityTypeEvent'“尝试访问日历

标签 ios swift eventkit

我正在尝试使用 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。

最佳答案

好的,这里主要有两点错误 - 第一点已经在评论中讨论过。

首先:使用 .EventEKEntityType.Event 而不是 EKEntityTypeEvent

第二:更改完成处理程序的声明以接受 NSError? 而不是 NSError! 因为 the actual completion handler是这样定义的。

关于ios - 错误 "Use of unresolved identifier ' EKEntityTypeEvent'“尝试访问日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31494874/

相关文章:

ios - 如何使用 Swift 2.0 和 Sprite Kit 在 Facebook 上分享分数

swift - Spritekit 场景归档

ios - 适当情况下创建新的EKCalendar iOS

ios - 如何在 iOS 中分配提醒 (EKReminder)?

android - react-native-keyboard-aware-scroll-view 无法正常工作

ios - 有没有办法从主机应用程序获取应用程序组标识符并在 iOS 上共享扩展程序?

ios - 使用 QLPreviewController 显示来自网络的 Pdf

ios - 即使通过 cocoa pod 安装框架后也没有这样的模块

iphone - Facebook 安装的参数不返回数据

ios - 使用EventKit读取Google日历ical文件