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()
}
}