2015-10-16 2 views
3

Я пытаюсь установить напоминание и вам нужно получить доступ к методу типа сущности в Swift 2.0 для iOS9. Тем не менее, он дает мне ошибку:Как запросить методAccessToEntityType в Swift 2.0 iOS 9?

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

Этот код работает для Swift, но не Swift 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, это работает! –

Смежные вопросы