2015-10-16 88 views
3

我想设置提醒,并需要访问请求实体类型的方法在Swift 2.0 iOS9中。然而,它给我的错误:如何在Swift 2.0 iOS 9中requestAccessToEntityType方法?

Use of unresolved identifier

@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() 
    } 
} 

此代码为雨燕,而不是斯威夫特2.有没有人有这种类型的问题?

回答

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 
+1

thsnk,这个作品! –