In todays tutorial we’re going to build a very simple list that you can search by using the filter in an Array. The concept is really quite simple, but good to also be aware of for when you might decide to filter on the frontend of the app.
Lets begin by creating a data model that will contain a published array:
class DataModel: ObservableObject {
@Published var items: [String] = [
"Ford", "Vauxhall", "Ferrari", "Lamborghini", "Aston Martin", "Nissan", "Bentley"
]
}
The DataModel we use is a class. We conform to the ObservableObject protocol and use the @Published property wrapper. If the array of strings called items is changed, then the @Published property wrapper will notify any view that uses this ObservableObject that a change has happend. The view will then update.
[Read more…]