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)
}
}
你好,
获得错误";无法转换"ServiceModel"类型的值。Type"转换为所需的参数类型"ServiceModel"在ServicePagePreview(employeeGroup:ServiceModel(。我是否使用了错误的数据类型?
您在此处提供类型:ServicePageView(employeeGroup:ServiceModel(
我想你是想在ServiceModel((中给出一个实例这将是返回该类型的实例的init。
您需要将代码包装在一个"身体;作为一个视图,像这样:
struct ServicePageView: View {
@ObservedRealmObject var employeeGroup: ServiceModel
var body: some View { // <--- here
...
}
}