skip to Main Content
struct ServicePageView: View {
    @ObservedRealmObject var employeeGroup: ServiceModel
    
    Section(header: Text("Select Employees: ")){
                List{
                    ForEach(employeeGroup.employeesList, id: .self){ employee in
                        Text(employee.firstName)
                     }
                }
            }

}

struct ServicePageView_Previews: PreviewProvider {
    static var previews: some View {
        ServicePageView(employeeGroup: ServiceModel)
    }
}

Hello,

Getting an error "Cannot convert value of type ‘ServiceModel.Type’ to expected argument type ‘ServiceModel’" at the ServicePagePreview(employeeGroup: ServiceModel). Am I using the wrong data type?

2

Answers


  1. You are supplying the type here:
    ServicePageView(employeeGroup: ServiceModel)

    I think you meant to give an instance as in ServiceModel()
    which would be an init returning an instance of the type.

    Login or Signup to reply.
  2. you need to wrap your code in a "body" to be a view, like this:

    struct ServicePageView: View {
        @ObservedRealmObject var employeeGroup: ServiceModel
    
        var body: some View {  // <--- here
           ...
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search