'List enumeration giving '()' cannot conform to 'View'

I have this view I'm working on:

struct MultipleSelectionRow: View {
    var title: String
    var isSelected: Bool
    var action: () -> Void

    var body: some View {
        Button(action: self.action) {
            HStack {
                Text(self.title)
                if self.isSelected {
                    Spacer()
                    Image(systemName: "checkmark")
                }
            }
        }
    }
}

struct FileSelectDialog: View {
    @Binding var files: [File]
    @State var selections: [Int]
    
    var body: some View {
        List {
            self.files.enumerated().forEach { (index, file) in
                MultipleSelectionRow(title: file.name, isSelected: self.selections.contains(index)) {
                    if self.selections.contains(index) {
                        self.selections.removeAll(where: { $0 == index })
                    } else {
                        self.selections.append(item)
                    }
                }
            }
        }
    }
}

But the generator I guess that's inside of the List inside of FileSelectDialog is giving me a () cannot conform to 'View' error. I'm not sure how else to do this. I need to keep track of the index inside of the forEach since these files are accessed using their index value. Is there something I'm missing? the ForEach is returning View objects so I'm not sure why Xcode is whining about it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source