struct NoteListView: View {
@ObservedObject var list: NoteList
var body: some View {
List {
ForEach($list.notes) { $note in
Text(note.foobar) // notice it says `note` and not `$note` – this is intentional
}
}
}
}
Running the above through SwiftFormat generates this:
struct NoteListView: View {
@ObservedObject var list: NoteList
var body: some View {
List {
ForEach($list.notes) { _ in
Text(note.foobar) // Cannot find 'note' in scope
}
}
}
}
Unless I'm mistaken, SwiftFormat incorrectly determines that $note is unused since I only use note and not $note. There are situations where you want to use $note as the parameter but still use just note, such as this:
ForEach($vm.items) { $item in
Button {
item.enabled.toggle() // this works, thanks to $item
} label: {
Text("\(item.name) is \(item.enabled ? "enabled" : "disabled")")
}
}
In this example, modified from an article from Swift by Sundell: https://www.swiftbysundell.com/articles/bindable-swiftui-list-elements/
Running the above through SwiftFormat generates this:
Unless I'm mistaken, SwiftFormat incorrectly determines that
$note
is unused since I only usenote
and not$note
. There are situations where you want to use$note
as the parameter but still use justnote
, such as this:It would not work without using
$item
.Am I correct in thinking this is a bug?