无法将 'ServiceModel.Type' 类型的值转换为预期的参数类型 'ServiceModel'


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
...
}
}

相关内容

  • 没有找到相关文章

最新更新