tableView function in iOS
override func tableView (tableView: UITableView,
commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
func tableView:
A table view is the scrolling thing that's containing all the dates in the
example project, and is a core component in iOS.
tableView: UITableView
contains two pieces of information:
tableView
is the name that we can use to reference the table view inside the method
UITableView
is the data type.
Everything that begins with "UI" is something Apple provides as part of its iOS development kit, so UITableView is the default Apple table view.
commitEditingStyle editingStyle: UITableViewCellEditingStyle
commitEditingStyle
is the actual action: this code will be triggered when the user tries to
commit the editing style of a table view. That means this code will be called
when the user tries to add or delete data from the table.
tableView: UITableView,
it meant we could reference the table view by using the "tableView" parameter,
but here the parameter is commitEditingStyle, which would be quite a clumsy
way to reference the parameter. So
Swift lets you give parameters external names:
one used when passing data in (commitEditingStyle, in this case) and
one to be used inside the method (editingStyle).
Finally, there's : UITableViewCellEditingStyle,
which means that the editingStyle parameter will be of data type UITableViewCellEditingStyle.
forRowAtIndexPath indexPath: NSIndexPath
Here's that sneaky parameter naming again,
people calling the method would write forRowAtIndexPath,
inside the method you would use just indexPath.
It's of data type NSIndexPath, which holds two pieces of information:
a table section and
a table row.
We aren't using sections here, but we are using rows – in the example project, every date
that is inserted is one row.