Daten aus Coredata Swift löschen

In meinem tableViewController habe ich folgendes. Und ich versuche, ein Element zum Arbeiten zu löschen.

var myData: Array<AnyObject> = []

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cellID: NSString = "Cell"
    var Cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellID) as UITableViewCell
    var data: NSManagedObject = myData[indexPath.row] as NSManagedObject
    Cell.textLabel?.text = data.valueForKeyPath("Name") as? String

    return Cell
}

Dann versuche ich zu löschen und habe.

override func tableView(tableView: (UITableView!), commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
        let cellID: NSString = "Cell"
        var Cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellID) as UITableViewCell
        var data: NSManagedObject = myData[indexPath.row] as NSManagedObject
        data.delete(0)

        // Delete the row from the data source
        //tableView!.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)


    } else if editingStyle == .Insert {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }
}

Antworten auf die Frage(7)

Ihre Antwort auf die Frage