Hi there,
I'm still new on learning how to code, so I'm seeking some guidance on this problem. I'm trying to make a page that shows a list of employees, I get an error reading
'Instance member 'data' cannot be used on type 'Employee'; did you mean to use a value of this type instead?'
Below is the code.
// AllEmployees.swift
import SwiftUI
struct AllEmployees: View {
let names = data.firstName
// Error shows on the next line ↓
@State private var data = Employee.data
@State private var searchText = ""
var body: some View {
NavigationStack {
List {
ForEach(data.firstName, id: \.self) { name in
NavigationLink {
Text(data.firstName)
} label: {
Text(name)
}
}
}
.searchable(text: $searchText)
.navigationTitle("All Employees")
}
}
var searchResults: [String] {
if searchText.isEmpty {
return names
} else {
return names.filter { $0.contains(searchText) }
}
}
}
struct AllEmployees_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
AllEmployees()
}
}
}
Any help is appreciated :)
3
0
3.9k