In Objective-C I have used the following code when deleting a row from a tableView and it works just fine.
Objective-C Example
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.arrayName removeObjectAtIndex:indexPath.row];
[self.tableName reloadData];
}
I recently made a search to see how this was done in Swift and I noticed that most of the code I found is different than what I used before.
Swift Example
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == UITableViewCellEditingStyle.Delete {
numbers.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
}
So now the question is, have I been doing it wrong or both ways are ok?
What is the correct way in either language (Swift or Objective-C)?