Ich verwende die NSUserDefaults, um ein Array (von Zeichenfolgen) zu speichern, und beim Laden scheint es als AnyObject anstelle von Array interpretiert zu werden. Ich verstehe nicht, wie das möglich ist, weil ich die ArrayForKey-Methode für meine Standardeinstellung verwende, von der ich dachte, dass sie ein Array zurückgeben soll.NSUserDefaults arrayForKey Wert von anyObject hat kein Mitglied removeAtIndex (Swift)
Der genaue Fehler Ich erhalte ist:
Wert vom Typ '[ANYOBJECT]?' hat kein Mitglied 'removeAtIndex'
die Dieses Array ist unveränderlich an shoppingListDefaults.arrayForKey("ShoppingList").removeAtIndex(indexPath.row)
let shoppingListDefaults = NSUserDefaults.standardUserDefaults()
let deleteAction = UITableViewRowAction(style: .Normal, title: "Delete") { (rowAction:UITableViewRowAction, indexPath:NSIndexPath) -> Void in
shoppingListDefaults.arrayForKey("ShoppingList").removeAtIndex(indexPath.row)
self.slItems.reloadData() // `slItems` is the IBOutlet for a UITableView
}
deleteAction.backgroundColor = UIColor.redColor()
return [deleteAction]