I'm trying to marry up what I see in the developer documentation with what I have just written, just so's I fully understand next time I write something like:
ForEach(expenses.items, id: \.name) { item in
Text(item.name)
}
.onDelete(perform: removeItems)
.
.
.
func removeItems(parameter1 offsets: IndexSet) {
expenses.items.remove(atOffsets: offsets)
}
It doesn't seem to matter what symbol, or underscore, I substitute for parameter1
, the function removeItems
is successfully performed by the ForEach.onDelete(perform:)
regardless of the parameter name in its signature.
Specifically, my question is about writing the signature of the function that is to be perform
ed :
When I see
@inlinable public func onDelete(perform action: ((IndexSet) -> Void)?) -> some DynamicViewContent
can I assume that I can, since my removeItems
function is being used as a closure - all Swift functions are closures, after all - that as long as it accepts one argument of type IndexSet
, it doesn't matter what name I give to the corresponding parameter.
Actually, in posting this, I think I've answered my own question. Mostly.
I assume that, since there is no overloading of perform
, and as it is being invoked as a closure, then there is no choice to be made between different signature "flavours" of perform
and thus a parameter name is not important and any will do - so long as there is one that the function can use.