How to call a view in SwiftUI?

Hello everyone, recently I started to learn the SwiftUI. Now I have this code but I don't understand how can I call a view in canvas? At the first case I have error which says that argument is missing.

import SwiftUI

struct EmployeeDetails: View {

    var employee: Employee

    var body: some View {

        VStack(alignment: .leading) {

            Text(employee.name)

                .font(.largeTitle)

                .foregroundColor(.primary)

            Text(employee.jobTitle)

                .foregroundColor(.secondary)

            EmailAddress(address: employee.emailAddress)
        }
    }
}

struct EmployeeDetails_Previews: PreviewProvider {

    static var previews: some View {

        EmployeeDetails()
    }
}

And when I use "employee" like argument in brackets, I have another error - can't find employee in scope.

struct EmployeeDetails_Previews: PreviewProvider {

    static var previews: some View {

        EmployeeDetails(employee)

    }
}

Please, help me to understand how can I call that view?

Answered by robnotyou in 703874022

When using EmployeeDetails(), you need to pass it an Employee.
e.g.

struct EmployeeDetails_Previews: PreviewProvider {
    static var previews: some View {
        let employee = Employee() /// However you create an Employee...
        return EmployeeDetails(employee: employee)
    }
}
Accepted Answer

When using EmployeeDetails(), you need to pass it an Employee.
e.g.

struct EmployeeDetails_Previews: PreviewProvider {
    static var previews: some View {
        let employee = Employee() /// However you create an Employee...
        return EmployeeDetails(employee: employee)
    }
}
How to call a view in SwiftUI?
 
 
Q