2015-09-13 1 views
0

En Xcode 6, ce code a bien fonctionné, mais dans Xcode 7gm, j'obtiens une erreur qui indique:erreur Downcast dans Xcode 7

Downcast de [UILocalNotification]? à '[UILocalNotification]' ne déballe que les options; vouliez-vous utiliser '!'?

L'erreur se produit pour la ligne où j'ai placé deux astérisques. Dans Xcode, il y a aussi un petit triangle rouge sous le a de la partie as!.

func removeItem(item: TodoItem) { 
    **for notification in (UIApplication.sharedApplication().scheduledLocalNotifications as! [UILocalNotification]) { // loop through notifications... 
     if (notification.userInfo!["UUID"] as! String == item.UUID) { // ...and cancel the notification that corresponds to this TodoItem instance (matched by UUID) 
      UIApplication.sharedApplication().cancelLocalNotification(notification) // there should be a maximum of one match on UUID 
      break 
     } 
    } 

Répondre

0

Dans Xcode 6 scheduledLocalNotifications est déclarée comme [AnyObject]! (baissés nécessaire).
Dans Xcode 7 scheduledLocalNotifications est déclarée comme [UILocalNotification]? (il suffit d'être déballés)

Je recommande d'utiliser les liaisons en option

func removeItem(item: TodoItem) { 
    if let scheduledLocalNotifications = UIApplication.sharedApplication().scheduledLocalNotifications { 
    for notification in scheduledLocalNotifications { // loop through notifications... 
    if (notification.userInfo!["UUID"] as! String == item.UUID) { // ...and cancel the notification that corresponds to this TodoItem instance (matched by UUID) 
     UIApplication.sharedApplication().cancelLocalNotification(notification) // there should be a maximum of one match on UUID 
     break 
    } 
    } 
} 
+0

qui ont fixé le! Merci beaucoup! – James