About Closure Basic Logic

struct ContentView: View {
    let items = ["Item 1", "Item 2", "Item 3"]

    var body: some View {
        VStack {
            List(items, id: \.self) { **item in**

I don't know why use Closure expression over there

Can I recall items like this?
a = [1,2,3]
func Name (i = a.count) {

Iā€™m not clear what the question is. Are you asking why List has a closure?

Not sure how the code you posted outside of the code block is relatable to your question.

No, VStack is a SwiftUI result builder, and is for Collecting other objects which conform to the View protocol.

The "print" function displays on the command line, which is not the main output area for a SwiftUI context.

For List, the closure takes a data item as supplied, allowing you to use it in the production of a new View object. Here, that object is a Text View.

1 Like