1) why do we use "at" in parameters? isnt it just an external name?
Yes, "at" is just an external name here. The only reason for using it is so that when we call the function, it can be read more naturally.
var unwantedIndexes = IndexSet()
//This can be read easily and a person can figure out what it does pretty well as they read it
removeRows(at: unwantedIndexes)
//This could be more confusing to read and understand
removeRows(offsets: unwantedIndexes)
2) what is atOffsets?
atOffsets is of type IndexSet
which means that it is basically a Set
of Int
values.
When we are removing a single row, the IndexSet
only has one Int
in it, and that Int
represents the index (position in the array or collection) that you want to remove.
However, if we want to delete multiple items at once, an IndexSet
containing all of the indexes (positions in the array or collection) that we want to be removed would be used.
3) the onDelete modifier, how does it know we're deleting a specific part of our list?
When you use onDelete(perform:)
the perform
parameter must be of the type (IndexSet) -> Void
(A function that takes an IndexSet as a parameter and returns Void) and Swift will automatically provide the IndexSet
to the perform
function as a parameter, based on how the user has interacted with the interface.