Your First iOS and SwiftUI App · SwiftUI State | raywenderlich.com

hello, I am new here. I have searched sth about syntax of struct in Swift docs, and found the demo given looks like this

struct User {
    let firstName: String
    let lastName: String
    var email: String
    var isActive: Bool
    
    func printFullName() {
        print("\(firstName) \(lastName)")
    }
}

My question is What is the meaning by VStack including VStack syntax, does that mean a Struct can include a Struct?

VStack {
        VStack {
            Text("Welcome to my first App!")
                .underline(true, color: Color.blue)
                .foregroundColor(Color.green)
                .fontWeight(.semibold)
        }

Hi fuzheng1998,

The User struct is a customized data type with the struct used to model related data into one type. Instantiating User will require that its properties are all addressed:
let fuzheng = User(firstName: “fuz”, lastName: “heng”, email: “fuzhen@gmail.com”, isActive: true)

The VStack is a SwiftUI container. It is used to compose Views that arrange contents vertically. The SwiftUI VStack, HStack, and ZStack can be embedded within one another to create endless layouts.

I’ve built a simple example using the VStack, HStack and the User struct. It might help you gain a sense of how SwiftUI Views are composed and how a complex Type can be used, or maybe I am completely misunderstanding your question:

import SwiftUI

struct ContentView: View {
// @State private var user = User()

var body: some View {
    VStack {
        VStack {
            Text("Welcome to my first App!")
                .underline(true, color: Color.blue)
                .foregroundColor(Color.green)
                .fontWeight(.semibold)
        }
        
        HStack {
            Text("Left")
            Spacer()
            Text("Right")
        }
        .padding()
        
        HStack {
            Text(fuzheng.firstName)
            Text(fuzheng.lastName)
        }
        HStack {
            Text(ron.firstName)
            Text(ron.lastName)
        }
    }
}

}

let fuzheng = User(firstName: “fuz”, lastName: “heng”, email: “fuzhen@gmail.com”, isActive: true)

let ron = User(firstName: “Ron”, lastName: “Parker”, email: “abc@abc.com”, isActive: true)

struct User {
let firstName: String
let lastName: String
var email: String
var isActive: Bool

func printFullName() {
    print("\(firstName) \(lastName)")
}

}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}