我正在尝试设置提醒,并且需要在Swift 2.0 for iOS9中访问实体类型方法的请求。但是,它给了我错误:
使用未解析的标识符
@IBAction func setReminder(sender: AnyObject) {
appDelegate = UIApplication.sharedApplication().delegate
as? AppDelegate
if appDelegate!.eventStore == nil {
appDelegate!.eventStore = EKEventStore()
appDelegate!.eventStore!.requestAccessToEntityType(EKEntityTypeReminder, completion: {(granted, error) in //use of unresolved identifier EKEntityTypeReminder
if !granted {
println("Access to store not granted")
println(error.localizedDescription)
} else {
println("Access granted")
}
})
}
if (appDelegate!.eventStore != nil) {
self.createReminder()
}
}
此代码适用于Swift,但不适用于Swift 2.是否有人遇到此类问题?
答案 0 :(得分:5)
EKEntityType
现在是enum
,其中包含两种可以指定的类型。
EKEntityTypeReminder
:
appDelegate!.eventStore!.requestAccessToEntityType(EKEntityType.Reminder, completion:
{(granted, error) in
if !granted
{
println("Access to store not granted")
println(error.localizedDescription)
}
else
{
println("Access granted")
}
})
或者只是:
.Reminder