如何在Swift 2.0 iOS 9中请求AccessToEntityType方法?

时间:2015-10-16 11:43:11

标签: ios swift2 ios9 eventkit

我正在尝试设置提醒,并且需要在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.是否有人遇到此类问题?

1 个答案:

答案 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