That addresses this use case:
Button("Duplicate") {
let newItem = with(myModel.items[selectedRowIndex]) {
$0.name += " copy"
}
myModel.insert(newItem)
}
But it doesn’t address this use case:
Button("Edit").sheet(…, onDismiss:
let newItem = with(myModel.items[selectedRowIndex]) {
$0.name += newName
$0.unitPrice += newPrice
$0.upc = newUPC
}
myModel.items[selectedRowIndex] = newItem
})
The second accesses myModel.items[selectedRowIndex] twice and makes an unnecessary copy. Is the first pattern really so much more common than the second?